Featured post
.net - Possible bug in Html.DropDownList, selected values not reflecting? -
i know has been asked few times before, existing solutions hacks rather proper pattern.
i have simple drop down list. trying populate data , have item pre selected. succeeding @ 'populate data part' failing preferred item pre-selected.
i using asp.net mvc 3 rc2.
the important code bits:
{ // bunch of code categoryoptions = new selectlist(categories, "id", "slug", article.category.id); }
now... categoryoptions being passed html helper so:
@html.dropdownlistfor(a => a.category, model.categoryoptions)
i have looked @ values being passed helper , have confirmed 1 of items has selected value set true:
however, not reflecting in html being generated helper. none of ... tags have selected="selected" attribute.
i used reflector examine code bit, , line (selectextensions.selectinternal) looks dicey:
item.selected = (item.value != null) ? set.contains(item.value) : set.contains(item.text);
am doing wrong here? or framework (asp.net mvc 3 rc2) @ fault here.
ok... fixed it.
i changed around view model use categoryid instead of category slug. now, view looks like:
@html.dropdownlistfor(a => a.categoryid, model.categoryoptions, new { @class = "ask-category-field" })
i think model value being select (in case, => a.categoryid) has have same type selected 'value.' (i refine explanation when more time go on framework code.) clever coding indeed :) hats of asp.net mvc devs.
now, works expect , retains changes selected item across prg lifecycle.
hope helps someone.
- Get link
- X
- Other Apps
Comments
Post a Comment