Asp.net Mvc + Populate Dropdownlist
In my viewModel I have: public class PersonViewModel { public Person Person { get; set; } public int SelectRegionId { get; set; } public IEnumerable
Solution 1:
Your ViewModel has a property of type 'IEnumerable', but SelectList does not satisfy that type. Change your code like this:
publicclassPersonViewModel
{
public Person Person { get; set; }
publicint SelectRegionId { get; set; }
public SelectList Regions { get; set; }
}
View:
<div class="form-group">
@Html.LabelFor(model => model.Person.Address.Region)
@Html.DropDownListFor(model => model.SelectRegionId, Model.Regions, "Choose... ")
</div>
Post a Comment for "Asp.net Mvc + Populate Dropdownlist"