8

I have a class. At one point, I had set the properties of the class to [Required] using System.ComponentModel....

Okay, then I realized this was not needed. I have removed the required property but when I try to submit the form to an ActionResult the form does NOT post and still is trying to enforce the TextBoxFor(theModelProperty) to be populated.

I have deleted the "obj" folder, the "bin" folder, and also "Cleaned" the solutions. Still NO resolution.

I don't want to do a stupid workaround, I would like to do things correctly. Any idea why this occurs?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Robert Green MBA
  • 1,834
  • 1
  • 22
  • 45

2 Answers2

17

You have two options:

  1. Set property as nullable,
  2. Turn off required attribute for value types (see this answer)
Community
  • 1
  • 1
frennky
  • 12,581
  • 10
  • 47
  • 63
  • Hey, thanks very much. That worked perfectly. Can you help me out with the following? :-) [link](http://stackoverflow.com/questions/6815653/my-working-application-mvc3-razor-unexplainably-stopped-working-iis-7) – Robert Green MBA Jul 25 '11 at 12:04
1

If you have value type properties. Client validation will always generate required validations. If you don't want required validation for value types make them nullable.

Wim
  • 1,967
  • 11
  • 19