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

asp.net-mvc – 使用ASP.NET MVC v2 EditorFor和DisplayFor与IEn

发布时间:2020-12-15 19:42:01 所属栏目:asp.Net 来源:网络整理
导读:我有一个IList Tag作为我的模型中命名为标签的属性。当我调用DisplayFor或EditorFor时,如何命名显示和编辑器模板的文件?用法: 模型 class MyModel { IListTag Tags { get; protected set; }} 视图 %= Html.EditorFor(t = t.Tags) % 编辑 我知道我可以做到
我有一个IList< Tag>作为我的模型中命名为标签的属性。当我调用DisplayFor或EditorFor时,如何命名显示和编辑器模板的文件?用法:

模型

class MyModel 
{
    IList<Tag> Tags { get; protected set; }
}

视图

<%= Html.EditorFor(t => t.Tags) %>

编辑
我知道我可以做到这一点,但它不是我想做的。

<%= Html.EditorFor(t => t.Tags,"TagList") %>

解决方法

使用属性[UIHint(“Tags”)],然后在DisplayTemplates文件夹中创建一个名为Tags.ascx的显示模板。
class MyModel 
{
    [UIHint("Tags")]
    IList<Tag> Tags { get; protected set; }
}

并在文件中的Tags.ascx

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Tag>>" %>
<!-- put your Model code here ->

为我工作

(编辑:李大同)

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

    推荐文章
      热点阅读