I’m building my first MVC application after years of doing webforms, and for some reason I am not able to make this work:
@Html.DropDownList("PriorityID", String.Empty, new {@class="textbox"} )
Error message:
System.Web.Mvc.HtmlHelper<SPDR.Models.Bug>‘ does not contain a definition for DropDownList and the best extension method overload System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>, object) has some invalid arguments
Any help greatly appreciated!
Looking at the controller, and learing a bit more about how MVC actually works, I was able to make sense of this.
My view was one of the auto-generated ones, and contained this line of code:
To add html attributes, I needed to do something like this:
Thanks again to @Laurent for your help, I realise the question wasn’t as clear as it could have been…
UPDATE:
A better way of doing this would be to use DropDownListFor where possible, that way you don’t rely on a magic string for the name attribute