Hard coding the Drop Down List
Fillling DropDownList with Database data
Countries
@Html.DropDownList("Countries",
new List<SelectListItem> {
new SelectListItem {Text = "India" },
new SelectListItem {Text = "US" }
})
Fillling DropDownList with Database data
public ActionResult Index()
{
ContactGroups cg = new ContactGroups();
var cgs = cg.GetGroups();
ViewBag.groups =new SelectList(cgs,"GroupId","GroupName");
return View();
}
<div>
@Html.DropDownList("groups", "select Group")
</div>
Here groups is the name of ViewBag.
No comments:
Post a Comment