5

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

How 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?

Neil
  • 2,688
  • 1
  • 23
  • 32
  • I have same problem, I needed to check multiple values so I mad a class level custom attribute but I get nothing back to the view showing that I have an error. I am getting the impression that using data annotations for model validation is lack luster at best. – JBeckton Jan 20 '11 at 19:07
  • This question http://stackoverflow.com/questions/4266632/unable-to-set-membernames-from-custom-validation-attribute-in-mvc2 has same problem and a solution also hope tat helps. – Vipresh Jan 03 '12 at 14:03

1 Answers1

0

How about checking ModelError.Exception in IModelBinder.OnModelUpdated.

takepara
  • 10,413
  • 3
  • 34
  • 31