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!
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