After adding the class to the html.dropdownlist am facing the below error.
Error:‘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
<li>
@Html.LabelFor(m => m.BuildType)
@Html.DropDownList("BuildType", new { @class = "BuildType" })
@Html.ValidationMessageFor(m => m.BuildType)
</li>
<li>@Html.LabelFor(m => m.BuildMode)
@Html.DropDownList("BuildMode", new { @class = "BuildMode" })
@Html.ValidationMessageFor(m => m.BuildMode) </li>
<li>
You can use:
or
When you use
@Html.DropDownList, you specify a name for the dropdownlist… but you are missing the SelectList itself. I think that out of the box, the helper will try to use the name of the DropDownList (in your case “BuildType”) to search in the ViewData collection for the SelectList.When you use a
@Html.DropDownListForyou don’t use a name, but a lamda expressionm => m.BuildTypethat will help you in same cases to not have harcoded names.Your
SelectList(the second parameter) can be grabbed fromViewbagor from a property in yourModel.