MVC3 Remove ModelState Errors

后端 未结 5 1590
-上瘾入骨i
-上瘾入骨i 2020-12-04 11:56

I\'ve got a situation where I\'m uploading an image the user has selected from his local file system. My Form in my view, basically has two submit buttons. One is used to

5条回答
  •  眼角桃花
    2020-12-04 12:32

    I use it sometimes, so I've made an extension method out of it:

    public static ModelStateDictionary ClearError(this ModelStateDictionary m, string fieldName)
    {
        if (m.ContainsKey(fieldName))
            m[fieldName].Errors.Clear();
        return m;
    }
    

    It can be used fluently to clear error for multiple fields.

提交回复
热议问题