23 lines
701 B
C#
23 lines
701 B
C#
using EnVisage.Code.Extensions;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
|
|
namespace EnVisage.Code.Validation
|
|
{
|
|
public class ValidateAjaxAttribute : ActionFilterAttribute
|
|
{
|
|
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
|
{
|
|
if (!filterContext.HttpContext.Request.IsAjaxRequest())
|
|
return;
|
|
|
|
var modelState = filterContext.Controller.ViewData.ModelState;
|
|
if (!modelState.IsValid)
|
|
{
|
|
filterContext.Result = new FailedJsonResult(modelState);
|
|
filterContext.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |