문제

I have an ASP.NET MVC application that is using a single view to display the properties and children (with their properties) of a model entity.

My model looks something like this:

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; }
}

On the view, I want to use a table to display the list of related email addresses. To do this, I am using 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") %>

However, when I do this, the hidden ID is that of the parent entity Market, not that of the EmailAddress.

How do I remedy this?

도움이 되었습니까?

해결책

It seems it could be a bug in the WebGrid. Have you tried renaming your ID field in the EmailAddress class, e.g. EmailID and pass that to the WebGrid and see if it displays correctly?

다른 팁

This works for me, could it be that you have something wrong in the filling of your model?

Since you're using the lambda expression for the Column.For() method, the x parameter is re referring to a single email. I think you mean to refer to the Model, not a single email ID

Instead of doing x.ID, I think you just want Model.ID

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top