MVC2 html dropdownlist is invisible
- by Deb
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 ?