MVC2 html dropdownlist is invisible
Posted
by
Deb
on Stack Overflow
See other posts from Stack Overflow
or by Deb
Published on 2012-04-03T11:04:33Z
Indexed on
2012/04/03
11:30 UTC
Read the original article
Hit count: 219
asp.net-mvc
I am just trying to populate a html.dropdown list using mvc2 in VS2008.
But the control is not displayed at all.
Here is my code
public ActionResult Index()
{
ViewData["Time"] = DateTime.Now.ToString();
var mdl = new List<SelectListItem>();
mdl.Add(new SelectListItem
{
Value = "1",
Text = "Module One"
});
mdl.Add(new SelectListItem
{
Value = "2",
Text = "Module Two"
});
ViewData["moduleList"] = new SelectList(mdl,"Value", "Text");
return View("MainMenu");
}
and here is the markup
<div>
<%Html.DropDownList("moduleList", (IEnumerable<SelectListItem>)ViewData["moduleList"]); %>
</div>
Where did i go wrong ?
© Stack Overflow or respective owner