我创建了一个显示模板,当传递一个字符串时会呈现一个禁用的文本框
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %> <%: Html.TextBoxFor(model => model,new { disabled = "disabled" })%>
哪个效果很好.但是,出于某种原因,MVC想要通过它来尝试填充DateTimes和Ints,这会抛出异常
The model item passed into the dictionary is of type ‘System.Int32’,but this dictionary requires a model item of type ‘System.String’.
有任何想法吗?
解决方法
您不需要强烈地将模板键入String.
你可以尝试这样的事情:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <%= Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue,new { disabled = "disabled" }) %>
在你看来,你这样称呼它
Html.DisplayModelFor(model => mode.name);
有关更多信息,请参阅他在MVM中的模板系列中的Brad Wilson article中字符串的默认内置编辑器模板示例.
你应该考虑完成整个系列.我无法表达这个系列对我有多大帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。