For example in your controller:
public ActionResult MyDropDownList()
{
ViewBag.MyType = GetDropDownList();
return View("");
}
public static List
{
var ls = new List
{
new SelectListItem() {Text = "Bob", Value = "0"},
new SelectListItem() {Text = "Jeff", Value = "1"},
new SelectListItem() {Text = "Rob", Value = "2"}
};
return ls.OrderBy(x => x.Text).ToList();
}
In your razor script/cshtml:
@Html.DropDownList("MyType", MyController.GetDropDownList())
Hopefully that will help you to get your populated dropdown list :)
for (var i = 0; i <= 10; i++)
{
amountList.Add(new SelectListItem { Text = i.ToString(CultureInfo.InvariantCulture), Value = i.ToString(CultureInfo.InvariantCulture) });
}
amountList = amountList.ToList();
}
@Html.DropDownListFor(model => model.ReceptionRooms, amountList)
@Html.ValidationMessageFor(model => model.ReceptionRooms)
No comments:
Post a Comment