Removing Required Attribute from Class but MVC3 still won't post the form without a value in the text box

孤街醉人 提交于 2019-12-01 00:28:51

问题


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?


回答1:


You have two options:

  1. Set property as nullable,
  2. Turn off required attribute for value types (see this answer)



回答2:


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.



来源:https://stackoverflow.com/questions/6814853/removing-required-attribute-from-class-but-mvc3-still-wont-post-the-form-withou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!