asp.net - Using 5th overload of Html.DropDownList causes exception. (does not contain a definition for 'DropDownList' and the best extension method overload..) -
i have model property
public list<system.web.mvc.selectlistitem> responsetypes { get; set; } and in view have on view causes error
error cs1928: 'system.web.mvc.htmlhelper' not contain definition 'dropdownlist' , best extension method overload 'system.web.mvc.html.selectextensions.dropdownlist(system.web.mvc.htmlhelper, string
@html.dropdownlist("responsetypeid", "--select response type--", question.responsetypes, new { @class = "form-control responsetype", @id = "cbxtype" }) i trying use overload
public ihtmlstring dropdownlist(string name, string defaultoption, ienumerable<selectlistitem> selectlist, idictionary<string, object> htmlattributes); i can't seem figure out what's wrong code. believe have followed overload properly.
i have tried casting it. still doesn't work though.
@html.dropdownlist("responsetypeid", "--select response type--", (ienumerable<selectlistitem>)question.responsetypes, new { @class = "form-control responsetype", @id = "cbxtype" })
your using method in system.web.webpages.html namespace, not system.web.mvc namespace.
what need use this overload signature is
public static mvchtmlstring dropdownlist( htmlhelper htmlhelper, string name, ienumerable<selectlistitem> selectlist, string optionlabel, object htmlattributes ) so code in view be
@html.dropdownlist("responsetypeid", question.responsetypes, "--select response type--", new { @class = "form-control responsetype", id = "cbxtype" }) however recommend use typed
@html.dropdownlistfor(m => m.responsetypeid, question.responsetypes, "--select response type--", new { @class = "form-control responsetype", id = "cbxtype" })
Comments
Post a Comment