VIEW: Pass viewdata attribute in dropdownlist html designing code
Html.DropDownList("CarsList", new SelectList((IEnumerable)ViewData["CarsList"], "ID", "Name"))
CONTROLLER: first get required data from database and then pass the resultant data to view from controller using viewdata attribute
public ActionResult GetData()
{
var CarNames = from c in obj.Cars
select c;
ViewData["Carsist"] = CarNames;
return View();
}
Posted by:
T.Saravanan
on: 9/5/2012
Level:Silver | Status: [Member] [MVP] | Points: 10
Kindly post your code inside the code tag.
@using (Html.BeginForm("BindHRlist", "Appraisal", FormMethod.Post))
{
<div style="float: left; width: 100%">
<br />
<div>
Account:
@Html.DropDownList("CarsList", new SelectList((System.Collections.IEnumerable)ViewData["CarsList"], "Id", "Name"), new { id = "ddlCars" })
</div>
}