Using DropDownlist in MVC4
In MVC ddl Is Collection Of Selectlistitem Objects In create Method 1: In View: @ Html.DropDownList( "BranchID" , String .Empty) In controller: ViewBag.BranchID = new SelectList (db.M_Branches, "ID" , "BranchName" ); Method 2: to get the “select” option in ddl In View: @ Html.DropDownListFor(model => model.BranchID, ( IEnumerable < SelectListItem >)ViewBag.BRANCHVAL, "Select" ) In controller: ViewBag.BRANCHVAL = new SelectList (db.M_Branches, "ID" , "BranchName" ); In Index: To bind ddl from different table/storeprocedure Method 1: In View: · Using ViewBag @ Html.DropDownList( "ddllocation" , ( IEnumerable < SelectListItem >)ViewBag.location, "Select" ) Using ViewData @ Html.DropDownList( "ddlDepartments" ,ViewData[ "Locations" ] as IEnumerable < SelectListItem >, "Select...