Skip to content Skip to sidebar Skip to footer

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>

Solution 2:

You are creating SelectList instance twice. Get rid of one of them:

@Html.DropDownListFor(model => model.SelectRegionId, Model.Regions, "Choose... ")

Post a Comment for "Asp.net Mvc + Populate Dropdownlist"