我也需要在MVC 4上实现“部分验证技术”,如this answer中所述:

      public class DontValidateEmailAttribute : ActionFilterAttribute  
         {  public override void OnActionExecuting(ActionExecutingContext filterContext)  
                 { 
                    var modelState = filterContext.Controller.ViewData.ModelState;      
                    var incomingValues = filterContext.Controller.ValueProvider;     
                    var key = modelState.Keys.Single(x => incomingValues.Equals("Email")); 
                    modelState[key].Errors.Clear();   
                  } 
          } 

但是我得到以下 编译错误:“ 'System.Collections.Generic.ICollection<string>' does not contain a definition for 'Single' and no extension method 'Single' accepting a first argument of type 'System.Collections.Generic.ICollection<string>' could be found (are you missing a using directive or an assembly reference?) ...”

谢谢

请您参考如下方法:

您在顶部缺少using System.Linq吗?


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!