asp.net - HTML helper DropDownList explained -
can please explain how works? (which overload being used)
@html.dropdownlist("financialyearid", "select fy") financialyearid selectlist in view bag. why passed string?
also how can add custom attributes on input element? adding 3rd parameter
new { @class = "foo" } doesn't work?
is possible add data- attributes using default helpers?
thanks
you're calling this overload. creates dropdown list name "financialyearid" (which means selected value bind model or viewbag property called "financialyearid") , "select fy" placeholder (empty) selection text.
if want add class, need dropdown(string, ienumerable, string, object) helper:
@html.dropdownlist("financialyearid", null, "select fy", new { @class = "foo" }) here, can populate dropdownlist passing in ienumerable (such selectlist) have passed null.
yes, entirely possible pass data attribute. replace hyphen underscore:
@html.dropdownlistfor("financialyearid", null, "select fy", new { @data_something = "foo" }) if have model property you're trying bind selected value, can pass lamba expression indicate property want bind , framework generate appropriate name:
@html.dropdownlist(m => m.financialyearid, myselectlist, "select fy", new { @data_something = "foo" }) i'd advise putting selectlist in model on initial request rather using viewbag.
Comments
Post a Comment