Problems with Html.DropDownList

Problems with Html.DropDownList

February 25th, 2009  |  Published in Programming

I guess I should say that this issue is not as bad as the cat with the Rubiks Cube but, I like the pic.

I posted this on a couple of boards with no real answer so I thought I would post it here to see if anyone can give me any insight in to how to approach this problem.

Controllers:

public ActionResult Test()
{
ViewData["MonitoringType"] = new SelectList(myModel.GetMonitoringType(), "Category", "Category");
return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Test(FormCollection formValues)
{
ViewData["MonitoringType"] = new SelectList(myModel.GetMonitoringType(), "Category", "Category", formValues["MonitoringType"]);
return View();
}

And not surprisingly this works:

<%= Html.DropDownList("MonitoringType")%>

and this doesn’t

<%= Html.DropDownList("MonitoringType", (SelectList)ViewData["MonitoringType"],new {style = "width: 300px;"})%>

Currently, my workaround is to implement the first version and then use jQuery add attributes on the fly.



Related Posts

Flowing Data Charts Using Dundas/Microsoft Charts
ASP.NET MVC Links
Haack MVC Video: Cross-site Request Forgery Attack
Updating Drop Downs w/ ASP.NET MVC and jQuery

Archives