Модель:
public class SomeClass
{
public int SomeClassID { get; set; }
}
public class AnotherClass
{
public int AnotherClassID { get; set; }
public int AnotherClassText { get; set; }
}
public class MyViewModel
{
public SomeClass SomeClass { get; set; }
public List<AnotherClass> AnotherClasses { get; set; }
}
Контроллер:
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new MyViewModel
{
AnotherClasses = new[]
{
new AnotherClass { AnotherClassID = 1, AnotherClassText = 1 },
new AnotherClass { AnotherClassID = 2, AnotherClassText = 2 },
new AnotherClass { AnotherClassID = 3, AnotherClassText = 3 },
}.ToList()
};
return View(model);
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
// TODO:
return View(model);
}
}
Вид:
<%= Html.DropDownListFor(x => x.SomeClass.SomeClassID,
new SelectList(Model.AnotherClasses, "AnotherClassID", "AnotherClassText"))%>