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

asp.net-mvc – 使用HTML.Grid显示子对象

发布时间:2020-12-16 09:50:13 所属栏目:asp.Net 来源:网络整理
导读:我有一个ASP.NET MVC应用程序,它使用单个视图来显示模型实体的属性和子项(及其属性). 我的模型看起来像这样: public class Market{ public int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public IListEm
我有一个ASP.NET MVC应用程序,它使用单个视图来显示模型实体的属性和子项(及其属性).

我的模型看起来像这样:

public class Market
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public IList<EmailAddress> EmailAddresses { get; set; }
}
public class EmailAddress 
{
    public virtual int ID { get; set; }
    public virtual int MarketID { get; set; }
    public virtual string Email { get; set; }
}

在视图中,我想使用表来显示相关电子邮件地址的列表.为此,我使用的是Html.Grid.

<%= Html.Grid(Model.EmailAddresses).Columns( column =>
    {
        column.For(x => x.Email + Html.Hidden("ID",x.ID)).Encode(false).Sortable(false);
    })
    .Attributes(style => "width:100%")
    .Attributes(id => "emailGrid")
    .Empty("There are no Email Addresses set up") %>

但是,当我这样做时,隐藏的ID是父实体Market的ID,而不是EmailAddress的ID.

我该如何解决这个问题?

解决方法

它似乎可能是WebGrid中的一个错误.您是否尝试在EmailAddress类中重命名您的ID字段,例如EmailID并将其传递给WebGrid并查看它是否正确显示?

(编辑:李大同)

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

    推荐文章
      热点阅读