You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ValidateModelStateAttribute.cs 576B

12345678910111213141516171819
  1. using System.Net;
  2. using System.Net.Http;
  3. using System.Web.Http.Controllers;
  4. using System.Web.Http.Filters;
  5. namespace iiie.WebApiUtils.BusinessManager
  6. {
  7. public class ValidateModelStateAttribute : ActionFilterAttribute
  8. {
  9. public override void OnActionExecuting(HttpActionContext actionContext)
  10. {
  11. if (!actionContext.ModelState.IsValid)
  12. {
  13. actionContext.Response = actionContext.Request.CreateErrorResponse(
  14. HttpStatusCode.BadRequest, actionContext.ModelState);
  15. }
  16. }
  17. }
  18. }