Create Filter
public sealed class ValidateOnlyIncomingValuesAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)//OnActionExecuted
{
var modelState = filterContext.Controller.ViewData.ModelState;
var valueProvider = filterContext.Controller.ValueProvider;
var keysWithNotIncommingValue = modelState.Keys.Where(x => !valueProvider.ContainsPrefix(x));
foreach (var key in keysWithNotIncommingValue)
{
modelState[key].Errors.Clear();
}
}
}
Comments
Post a Comment