我有一个带有3个局部视图和视图模型的视图,我带有主视图
视图模型:
public class FactoryViewModel{
public FactoryViewModel()
{
FactoryA = new FactoryA();
FactoryB = new FactoryB();
FactoryC = new FactoryC();
}
public FactoryA FactoryA { get; set; }
public FactoryB FactoryB { get; set; }
public FactoryC FactoryC { get; set; }
}
View.cshtml:
@model Problem.Models.FactoryViewModel
@using (Html.BeginForm())
{
@Html.EditorFor(@Model.FactoryA);
@Html.EditorFor(@Model.FactoryB);
@Html.EditorFor(@Model.FactoryC);
}
工厂型号:
public abstract class Factory
{
public Factory()
{
Projects = new List<Project>();
Manager = new Person();
}
public string Description { get; set; }
public Person Manager { get; set; }
IList<Project> Projects { get; set; }
}
我还有FactoryController,它有ActionMethod用于返回视图,而JsonResult用于从数据库中获取所有人。
我的编辑器模板为人员创建下拉选择。我的问题是:如何在editorTemplates中填写下拉列表?
我可以创建空的下拉列表并在主视图中从javascript填充它们? 如果我想使用viewmodel填充下拉列表,我如何将值赋给@ Html.EditorFor()?
答案 0 :(得分:1)
我对整件事情有错误的想法。编辑模板是解决方案
@using (Html.BeginForm())
{
@Html.EditorFor(m => m.FactoryA)
@Html.EditorFor(m => m.FactoryB)
@Html.EditorFor(m => m.FactoryC)
}