Option 1:
@Html.DropDownList("Gender", new List<SelectListItem>{
new SelectListItem{ Text="Male", Value="Male"},
new SelectListItem{ Text="Female", Value="Female"}
}, "Select Gender")
Option 2:
Controller
public ActionResult DropDownListExampleView()
{
var list = new List<SelectListItem>
{
new SelectListItem{ Text="Male", Value = "Male" },
new SelectListItem{ Text="Female", Value = "Female" },
new SelectListItem{ Text="Select Gender", Value = "0", Selected = true },
});
ViewData["ddList"] = list;
return View();
}
In View
@Html.DropDownList("Gender", ViewData["ddList"] as List<SelectListItem>)
@Html.DropDownList("Gender", new List<SelectListItem>{
new SelectListItem{ Text="Male", Value="Male"},
new SelectListItem{ Text="Female", Value="Female"}
}, "Select Gender")
Option 2:
Controller
public ActionResult DropDownListExampleView()
{
var list = new List<SelectListItem>
{
new SelectListItem{ Text="Male", Value = "Male" },
new SelectListItem{ Text="Female", Value = "Female" },
new SelectListItem{ Text="Select Gender", Value = "0", Selected = true },
});
ViewData["ddList"] = list;
return View();
}
In View
@Html.DropDownList("Gender", ViewData["ddList"] as List<SelectListItem>)
1 Comments
thanks bro you rocks!
ReplyDelete