This is my controller.I Need to validate the input parameters before the action method gets executed.The action method accepts the Json object but inside the method we will convert it into model object.Is it possible to validate the input as Model object in my custom action filter?ValidateParamFilterAttribute is my custom filter class and it should accept the action methods as a parameter .It should be generic so I don't need to repeat it for every action methods in my app.
public class InputValidationController : ApiController
{
[HttpPost][ValidateParamFilter(typeof(Users))]
public string SaveData([FromBody]JObject testdata )
{
}
}
My Custom Action Filter:
public class ValidateParamFilterAttribute: Attribute , IActionFilter
{
public ValidateParamFilterAttribute(Type type) {
//not able to proceed here
// the type parameter will take my modal classes.in this case it should be Users
}
public override void OnActionExecuting(HttpActionContext actionContext)
{
}
}
Model class:
public class Users
{
[Required(ErrorMessage ="Id field is mandatory")]
public int id { get; set; }
[Required][StringLength(10,ErrorMessage ="Name length can't be more than 10")]
public string Name { get; set; }
[Required][Phone][MaxLength(10)]
public string PhoneNumber { get; set; }
[Required][EmailAddress]
public string Email { get; set; }
}

