Is it possible to use Data Annotations to validate parameters passed to an Action method of a Contro
Posted
by dannie.f
on Stack Overflow
See other posts from Stack Overflow
or by dannie.f
Published on 2010-04-26T22:04:04Z
Indexed on
2010/04/26
22:13 UTC
Read the original article
Hit count: 168
I am using Data Annotations to validate my Model in ASP.NET MVC. This works well for action methods that has complex parameters e.g,
public class Params
{
[Required] string Param1 {get; set;}
[StringLength(50)] string Param2 {get; set;}
}
ActionResult MyAction(Params params)
{
If(ModeState.IsValid)
{
// Do Something
}
}
What if I want to pass a single string to an Action Method (like below). Is there a way to use Data Annotations or will I have to wrap the string into a class?
ActionResult MyAction(string param1, string param2)
{
If(ModeState.IsValid)
{
// Do Something
}
}
© Stack Overflow or respective owner