-1

I have made a web application in MVC Razor. When I post/submit the page DATA ANNOTATION validation fires on those fields also which was hidden/or not shown to user. As dataannodation [Required] validation are put on hidden properties also, I am getting False value on ModelState.IsValid. And since the project is on the verge of completion we can not change or remake the MODEL Class.

Please somebody suggest me how to achieve this..If my question is not clear please let me know.

talonmies
  • 70,661
  • 34
  • 192
  • 269

1 Answers1

0

You can use

ModelState.Remove("FieldName");

to remove entries in model state, that are related to hidden fields.

Please at least make sure, that safety of the system is not compromised by using [Bind(Exclude = "Property names")] attribute to disable binding of fields, that should not be sent from form.

LukLed
  • 31,452
  • 17
  • 82
  • 107