views:

19

answers:

2

Here's the error I get:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0411: The type arguments for method 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

<div class="editor-field">
    <%: Html.DropDownListFor(model => model.Country, ViewData["Countries"] as SelectList) %>
    <%: Html.DropDownListFor(Model.Country, ViewData["Countries"] as SelectList) %>
    <%: Html.ValidationMessageFor(model => model.Country) %>
</div>

The first DropDownListFor works great; the second gives me the exception. I'm curious as to why this is caused. If I type in Model directly, I still get a list of it's attributed. Why would this break?

Thanks for the help!

+3  A: 

The DropDownListFor expects a lambda expression (Actually an Expression<Func<TModel, TProperty>>). Model.Country is neither an expression nor a function so it won't work there.

Check MSDN SelectExtensions.DropDownListFor

dbemerlin
A: 

It has to do with the method signature of the helper method. Its for generic dynamic evaluation of the object.

You could write your own overload to the helper that takes only the feature you want.

Jonathan Bates