Comment selectionner un item dynamiquement dans un ComboBox en cshtml
Bonjour à tous,
Je suis en train d'apprendre MVC sans trop de problème jusqu’à maintenant.
Je sais binder un comboBox avec un ViewBag.
Dans mon Controller:
Code:
1 2 3
|
Product.ClientCollection clients = Product.ClientCollection.LoadAll();
ViewBag.Clients = clients; |
Dans ma view Edit.Cshtml
Code:
1 2
|
@Html.DropDownList("cbClient", new SelectList(ViewBag.Clients, "PkIdClient","Nom")) |
Je n'arrive pas à selectionner automatiquement mon client dans ma ComboBox quand ma View Edit se charge.
Pouvez-vous m'éclairer sur ce sujet.
Merci d'avance.