问题描述
我上课.曾经,我已经使用System.ComponentModel ...将类的属性设置为[Required].
I have a class. At one point, I had set the properties of the class to [Required] using System.ComponentModel....
好的,然后我意识到这是不需要的.我已经删除了必需的属性,但是当我尝试将表单提交给ActionResult时,表单没有发布,并且仍在尝试强制填充TextBoxFor(theModelProperty).
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.
我已经删除了"obj"文件夹,"bin"文件夹,并且还清理了"解决方案.仍然没有分辨率.
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?
推荐答案
您有两个选择:
- 将属性设置为
nullable
- 关闭值的必需属性 类型(请参见此答案) li>
- Set property as
nullable
, - Turn off required attribute for value types (see this answer)
这篇关于从类中删除必需的属性,但MVC3仍然不会在文本框中没有值的情况下发布表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!