开发者

ASP.NET MVC Class level custom data-annotation and ModelState keys

开发者 https://www.devze.com 2022-12-26 15:00 出处:网络
I have custom class level validation attribute, inheriting from ValidationAttribute, on my model. H开发者_Go百科ow come it doesn\'t register a key in the ModelState when its IsValid is false? I can s

I have custom class level validation attribute, inheriting from ValidationAttribute, on my model.

H开发者_Go百科ow come it doesn't register a key in the ModelState when its IsValid is false? I can see the the error message in the ModelState.Values collection, but the ModelState.Keys collection only shows an empty string "". Can I provide a key for it - presumably this is because its not assigned to a property?

I wanna be able to use ModelState.Remove in my controller to remove this error upon a certain condition, but I have no Key!

Any ideas?


How about checking ModelError.Exception in IModelBinder.OnModelUpdated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号