In my api, I have a controller that takes a string as an argument.
[HttpPost("{text}")]
public ActionResult PostSomething(string text){}
I want text
to be one of three valid strings, lets say "a", "b", "c"
. Is there a way to do this using some attribute or is the best way to simply have an if statment inside the controller?
Thank you in advance.
CodePudding user response:
In your simple scenario yes you can use attribute but it is better to follow Separation of Concerns principle and Single Responsibility Principle and extract all your validation logic into separate classes Validators in this will help using such framework as Fluent Validation