Thursday, January 10, 2019

another shape of Html.DropDownList in Razor

@Html.DropDownList("ddlCountryCodes", (SelectList) ViewBag.CountryCodes)

 
 

Also, here is an example of hydrating the SelectList...

List<Country> countries = repository.ActiveCountryCodes();
ViewBag.CountryCodes = new SelectList(countries, "ERPCode", "Name", "");

 
 

Note that the four parameters are:

  1. the collection
  2. the getsetter on the POCO for the dropdown behind-the-scenes value
  3. the getsetter on the POCO for the dropdown public-facing value
  4. the setting itself

No comments:

Post a Comment