Thursday, 17 October 2019

MVC/ web api Action filter

public class ValidateModelStateFilter : ActionFilterAttribute
{

public override void OnActionExecuting(HttpActionContext actionContext)
{
if (!actionContext.ModelState.IsValid)
{
actionContext.Response = actionContext.Request.CreateErrorResponse((HttpStatusCode)422, actionContext.ModelState);
}
}

}

No comments:

Post a Comment