Thursday, August 30, 2012

MVC razor pain with dropdowns

Took a little head banging against the wall with this one, probably my lack of exposure to the MVC @razor model.
                <div>
                Region  @Html.DropDownListFor(model => model.Region, Model.Regions)
                </div>
Simple enough...but for one reason and another I needed to change the model, and all of a sudden the currently selected 'Region' ws no longer being default selected on a repost.
                <div>
                Region  @Html.DropDownListFor(model => model.subclass1.Region, Model.Regions)
                </div>
at first it was the incorrect property declaration :-
public string Region =""; instead of public string Region { get; set; }
still not fixed...
moved a copy of Region from model.subclass1.Region back up a level to model.Region.

Working again....so I can only surmise that the @razor model isn't too keen on properties being on sublevels when used for the selected item in a dropdown list.




No comments:

Post a Comment