Wednesday, 13 November 2013

Static Dropdown List in MVC 4

A dropdownlist in MVC is a collection of selectlistitem objects.

Here i am going to explain, how to get a static dropdown list without getting values from database .

Go to Home Controller and add another action method named as Departments
and add view to Departments


Go to Departments.cshtml and write the following code.

@Html.DropDownList("Departments", new List<SelectListItem>
{
new SelectListItem{Text="IT",Value=""},
new SelectListItem{Text="HR",Value=""},
new SelectListItem{Text="Finance",Value=""},
new SelectListItem{Text="Accounts",Value=""}
},"Select Department") 



Now run the application and you will see the static dropdown list
































This is the sample example for Dropdown list

keywords:MVC 4 Dropdownlist,dropdownlist in mvc4,static drop down list in mvc , dropdownlist in mvc,mvc dropdownlist,MVC 3 Dropdownlist,Asp.Net MVC 4 Dropdownlist,generate sample dropdownlist in mvc 5,generate sample dropdownlist in mvc,how to create static dropdownlist in mvc 4,
,how to create static dropdownlist in mvc,,how to create static dropdownlist in mvc5