How do I use dropdownlistfor for this viewmodel?
public class ViewModel
{
public IEnumerable<Model1> model1{ get; set; }
}
public class Model1
{
public string Name { get; set; }
public int Id{ get; set; }
}
How should I do this?
@model Models.ViewModels.ViewModel
@Html.DropDownListFor(model => model.model1)
You can put the selected id into your viewmodel.
In the Controller:
In the view: