加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-2 – Asp.net Mvc显示String的模板,但现在每个简单

发布时间:2020-12-16 04:27:08 所属栏目:asp.Net 来源:网络整理
导读:我创建了一个显示模板,当传递一个字符串时会呈现一个禁用的文本框 %@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControlString" %%: Html.TextBoxFor(model = model,new { disabled = "disabled" })% 哪个效果很好.但是,出于某种原因,MVC想要
我创建了一个显示模板,当传递一个字符串时会呈现一个禁用的文本框
<%@ 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中字符串的默认内置编辑器模板示例.

你应该考虑完成整个系列.我无法表达这个系列对我有多大帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读