Drop Down List in Asp.Net MVC3 or MVC4
Hi Developers,
I
going to show the Dropdown List MVC3. How To bind and show the list in a view.
Model Property :
public string Empdomian
{ get; set; }
Employeee Controller :
Here I’m
creating a list of items to bind in drop down list and returning.
private List<SelectListItem> EmployeeDomainList()
{
var options = new List<SelectListItem>();
options.Add(new SelectListItem
{ Value = "Programmer", Text = " Programmer" });
options.Add(new SelectListItem
{ Value = "Designer", Text = " Designer " });
options.Add(new
SelectListItem { Value = "Tester", Text = " Tester " });
options.Add(new
SelectListItem { Value = "DBA", Text = "
DBA " });
options.Add(new
SelectListItem { Value = "NetworkAdmin", Text = " NetworkAdmin " });
return options;
}
Suppose if want to create a some data regarding
employee details. In Controller directly u can assign into a some ViewData or
ViewBag or Session. so here I’m showing using ViewData how to bind into
particular list of items.
In contoroller u can call the
method and assign into a ViewDate like this :
ViewData["EmpList"]
= new SelectList(EmployeeDomainList(),
"Value", "Text");
So now I’m
going to show the view how to retrieve the drop down list binding data.
View :
@Html.DropDownListFor(model =>
model. Empdomian, (IEnumerable<SelectListItem>)ViewData["EmpList "], "Select")
Happy Coding,,,,,,
Jagan Mohan
The Venetian® Casino Resort in Las Vegas, NV
ReplyDeleteVenetian® Casino Resort in Las Vegas, 양산 출장샵 NV. Shows, Entertainment, Travel + Leisure. Book online 순천 출장안마 & view deals 창원 출장샵 on The Venetian® 성남 출장안마 Casino Resort 서산 출장마사지 in Las