samedi 28 novembre 2015

Set selected item in selectlist

IEnumerable<Product> Get();

I get items and create collection of this objects

 public class Product
    {
        public int? ProductId { get; set; }
        public string ProductName { get; set; }
    }    

Name = new SelectList(Get(), "ProductId", "ProductName", model.Id)

 @Html.DropDownListFor(m => m.Id, Model.Name)

In Model

public int Id { get; set; }

public SelectList Name { get; set; }

Always on page selected item is first item

How I can set selected item by model.Id?

Aucun commentaire:

Enregistrer un commentaire