views:

2251

answers:

3

I had the following piece of code in a web app running on ASP.NET MVC Beta:

<%= Html.DropDownList("Instances", new { style="width:270px;", onchange = "UpdateReport(this)" }) %>

where "Instances" is a SelectList stored in ViewData, like so:

ViewData["Instances"] = new SelectList(instanceList, "Id", "ClientName", report.SelectedId);

After upgrading to MVC RC1, I get the following error in the DropDownList:

CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'DropDownList' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, string)' has some invalid arguments

I've updated my references to point to the correct (new) Mvc Dll's, and I've also updated Microsoft.Web.Mvc.dll to the RC MVC Futures dll from codeplex.

Can anyone help?

+1  A: 

The Html.DropDownList signature has changed a bit in the RC. The 2nd parameter is now the SelectList object, not the attributes object. You just need to change your view code to call the correct overload.

Craig Quillen
+2  A: 

try this:

<%= Html.DropDownList("Instances", (SelectList)ViewData["Instances"], new { style="width:270px;", onchange = "UpdateReport(this)" }) %>
Eric Ness
A: 

It's actually a combination of both those answers...

The second parameter does have to be the SelectList, however resolving the particular error you were getting requires you to also convert the ViewData object to a SelectList, per ericness' answer:

<%= Html.DropDownList("Instances", (SelectList)ViewData["Instances"], new { style="width:270px;", onchange = "UpdateReport(this)" })
Josiah I.