Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DropDownListFor binding
Message
 
 
À
14/01/2013 13:24:03
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Versions des environnements
Environment:
C# 5.0
Divers
Thread ID:
01562476
Message ID:
01562503
Vues:
31
>Given:
 public class LLProduct
>  {
>    public Guid Id { get; set; }
>    public String Name { get; set; }
>  }
>
>  public class ProductsViewModel
>  {
>    public LLProduct Product { get; set; }
>  }
and an MVC action
      Guid id = Guid.NewGuid();
>      List<LLProduct> list = new List<LLProduct>
>        {
>          new LLProduct{Id=Guid.NewGuid(),Name="One"},
>          new LLProduct{Id = id,Name = "Two"}
>        };
>      ViewBag.Selector = new SelectList(list, "Id", "Name");
>
>      var p = new LLProduct();
>      p.Id = id;
> 
>      ProductsViewModel pvm = new ProductsViewModel{Product = p};
>      return View(pvm);
then '@Html.DropDownListFor(x=>x.Product.Id,(SelectList)ViewBag.Selector)
>' selects the right item ("Two")
>
>If, however, I use 'p' as the parameter to the view (and change the model in the cshtml) then '@Html.DropDownListFor(x=>x.Id,(SelectList)ViewBag.Selector) shows "One" (no value selected in the generated html) ?

What do you mean by p as the parameter to the view? What exactly is the problem - the list doesn't show both entries?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform