【发布时间】:2010-04-23 09:13:33
【问题描述】:
我开始在 ASP.NET MVC 和强类型模板助手中使用 DataAnnotations。
现在我的观点中有这个(Snippet 是我的自定义类型,Created 是 DateTime):
<tr>
<td><%= Html.LabelFor(f => Model.Snippet.Created) %>:</td>
<td><%= Html.EditorFor(f => Model.Snippet.Created)%></td>
</tr>
DateTime 的编辑器模板是这样的:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %>
<%=Html.TextBox("", Model.ToString("g"))%>
但现在我想将整个 <tr> 放入编辑器模板中,所以我想在我的视图中包含这个:
<%= Html.EditorFor(f => Model.Snippet.Created)%>
在编辑器模板中有类似的东西,但我不知道如何为标签属性呈现for,对于我的示例,它应该是Snippet_Created,与文本框的id\name相同,所以伪代码:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %>
<tr>
<td><label for="<What to place here???>"><%=ViewData.ModelMetadata.DisplayName %></label></td>
<td><%=Html.TextBox("", Model.ToString("g"))%></td>
</tr>
Html.TextBox() 的第一个参数为空,并且正确生成文本框的 id\name。
提前致谢!
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-2 data-annotations