从类中删除必需的属性,但 MVC3 仍然不会在文本框中没有值的情况下发布表单
我有课。在某一时刻,我使用 System.ComponentModel 将类的属性设置为 [Required]...
好吧,然后我意识到这是不需要的。我已经删除了所需的属性,但是当我尝试将表单提交到 ActionResult 时,表单不会发布,并且仍然尝试强制填充 TextBoxFor(theModelProperty)。
我删除了“obj”文件夹、“bin”文件夹,还“清理”了解决方案。仍然没有解决。
我不想做一个愚蠢的解决方法,我想正确地做事。知道为什么会发生这种情况吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有两个选择:
类型(请参阅此答案)
You have two options:
nullable
,types (see this answer)
如果您有值类型属性。客户端验证将始终生成所需的验证。如果您不希望对值类型进行必要的验证,请将它们设置为可为空。
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.