Domanda

Ho un'applicazione ASP.NET MVC che utilizza una singola vista per visualizzare le proprietà ed i bambini (con le loro proprietà) di un'entità modello.

Il mio aspetto modello qualcosa di simile:

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

In vista, voglio utilizzare una tabella per visualizzare l'elenco degli indirizzi e-mail correlati. Per fare questo, sto usando 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") %>

Tuttavia, quando faccio questo, l'ID nascosto è quello dell'entità mercato genitore, non quello del EmailAddress.

Come faccio a porre rimedio a questo?

È stato utile?

Soluzione

Sembra che potrebbe essere un bug nel WebGrid. Hai provato di rinominare il campo ID nella classe EmailAddress, per esempio EmailID e passa che al WebGrid e vedere se viene visualizzato correttamente?

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top