在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 public class ActionFilter : IActionFilter 2 { 3 4 /// <summary> 5 /// action 执行之前 6 /// </summary> 7 /// <param name="context"></param> 8 public void OnActionExecuting(ActionExecutingContext context) 9 { 10 #region 全局 Model 验证过滤 11 if (context.ModelState.IsValid) return; 12 var result = new ResponseData<object>(); 13 foreach (var item in context.ModelState.Values) 14 { 15 foreach (var error in item.Errors) 16 { 17 result.Status = MessageInfo.StatusFailed; 18 result.Message = error.ErrorMessage; 19 if (string.IsNullOrEmpty(result.Message)) 20 { 21 result.Message = "Verification is not necessary."; 22 } 23 context.Result = new JsonResult(result); 24 break; 25 } 26 } 27 #endregion 28 } 29 }
|
请发表评论