I saw model validationfrom here (in the section:) Handling Validation Errors.
Below is a snippet of code in Web API
public class ValidateModel : ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.ModelState.IsValid == false)
{
actionContext.Response = actionContext.Request.CreateErrorResponse(
HttpStatusCode.BadRequest, actionContext.ModelState);
}
base.OnActionExecuting(actionContext);
}
}
The problem is upon validation of model, if there were any errors, an exception it assigns an model state invalid.
And after that, before moving on to the actual method (which is decorated with this attribute [ValidateModel]), the WebAPI simply returns a 400 request.
But how? Which function returns HTTP 400?
What happens after executing this method? Where is the control flow?
EDIT:
The action that I apply to this attribute is normal.
[ValidateModel]
public IHttpActionResult Post([FromBody]Request)
{
return Ok(SuccessMessage);
}