Saurav Gurjar

Saurav Gurjar

  • 1.3k
  • 385
  • 11.4k

Bind dropdown with selected value during edit time in MVC

Dec 10 2019 1:33 AM
Controller//
 
ViewBag.ddlprincepal = new SelectList(objentity.ddlPrincipal(), "PrincipalID", "PrincipalName");
ViewBag.ddlprincepalselected = new SelectListItem { Text = inventoryDetailobj[0].PrincipalName, Value = (inventoryDetailobj[0].PrincipalID).ToString(),Selected=true };
 
View
// 
 
@Html.DropDownList("ddlprincepal",ViewBag.ddlprincepal as SelectList ,ViewBag.ddlprincepalselected as string , new { @id = "ddlprincepal" }) 
 
 
 

Answers (4)