drop.cshtml Code
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
var listItems = new List<SelectListItem>();
listItems.Add(new SelectListItem { Text = String.Empty, Value = String.Empty });
foreach (var name in ViewBag.Names)
{
listItems.Add(new SelectListItem { Text = name, Value = name });
}
}
<h2>
Index</h2>
@Html.DropDownList("dropDownList", listItems)
Controller:
public ActionResult drop()
{
List<string> abc=new List<string>(2);
var q = from a in objContext.Details
select a;
foreach (var i in q)
{
abc.Add(i.Name);
}
ViewBag.Names = abc;
return View(q);
}