asp.net-mvc – 人们如何使用编辑器/显示模板与Html助手?

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 人们如何使用编辑器/显示模板与Html助手?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
只是想知道人们如何以及何时使用编辑器/显示模板与 Html助手.具体来说,我所说的是它用于渲染不同的UI控件而不是渲染实体.

例如,我有类似下面的atm:

<tr>
    <th><%= Html.LabelFor(x => x.ActivityTypeId) %></th>
    <td><%= Html.EditorFor(x => x.ActivityTypeList,"MultiSelectDropDownList")%></td>
</tr>
<tr>
    <th><%= Html.LabelFor(x => x.Name) %></th>
    <td><%= Html.EditorFor(x => x.Name) %></td>
</tr>
<tr>
    <th><%= Html.LabelFor(x => x.Description) %></th>
    <td><%= Html.DisplayFor(x => x.Description,"DisplayString")%></td>
</tr>

但是最近我想知道我是否应该这样做:

<tr>
    <th><%= Html.LabelFor(x => x.ActivityTypeId) %></th>
    <td><%= Html.MultiSelectDropDownList(x => x.ActivityTypeList)%></td>
</tr>
<tr>
    <th><%= Html.LabelFor(x => x.Name) %></th>
    <td><%= Html.EditorFor(x => x.Name) %></td>
</tr>
<tr>
    <th><%= Html.LabelFor(x => x.Description) %></th>
    <td><%= Html.DisplayString(x => x.Description)%></td>
</tr>

但是,如果我选择第二个选项是使用中间编辑器的重点…我将使用Html.TextBox,并且能够设置我喜欢的任何html属性.

我对人们在这里使用的模式感兴趣…有什么想法吗?

干杯
安东尼

解决方法

EditorFor和DisplayFor是MVC 2中最强大的方面,在我看来应该尽可能多地使用和滥用.

跳转到Brad Wilsons博客并查看如何扩展Object模板,以快速viewmodel中提取属性的基于约定的屏幕:
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-5-master-page-templates.html

我在当前的项目中使用这种技术,到目前为止,还没有为单个屏幕编写过一行HTML. :d

原文链接:https://www.f2er.com/aspnet/247385.html

猜你在找的asp.Net相关文章