我有一个Html.TextBox(),我需要使它在某些条件下禁用。使用TextArea它就像这样:
<%=primaryLang ? Html.TextArea("e.location",new { rows = 2,cols = 60 }) : Html.TextArea("e.location",cols = 60,disabled = "true" })%>
但是使用TextBox是不可能的:
<%=primaryLang ? Html.TextBox("e.startDate") : Html.TextBox("e.startDate",new { disabled = "true"})%>
它将在值中发出{disabled = true}。这是因为允许你传递HtmlAttributes的唯一功能也需要传递模型。此视图是强类型,模型将自动填入。
如果我像这样传递:
Html.TextBox("e.startDate",Model.e.startDate,new { disabled = "true"})
或者这样:
Html.TextBox("e.startDate",null,new { disabled = "true"})
GET版本将工作,但POST版本将发出NullReferenceException。以上似乎都有完全相同的效果。两者都将从GET模型中提供正确的数据。
如果我像这样离开它的欲望:
Html.TextBox("e.startDate")
它将正常工作,对于POST和GET …
为什么?任何方式来完成?
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。