我有一个partialView _BasicInfoPartView关联到BasicInfoModel。 这partialview包含一些输入和下拉列表如下:窗体mvc3剃刀partialview后
public class BasicInfoModel
{ public string Name { get; set; }
public string selectedRubric { get; set; }
public IEnumerable<SelectListItem> Rubrics { get; set; }
}
部分_BasicInfoPartView.cshtml
@model ProjectZeroWebSite.Models.PleGroupModel
@Html.ListBoxFor(m => m.selectedRubric, @Model.Rubrics })
@Html.TextBoxFor(m => m.Name)
这partialview可以在任何页面的形式调用。只需要在页面模型中添加BasicInfoModel。
public class RandomPageModel
{
public basicInfoModel { get; set; }
public string info2{ get; set; }
...
public RandomPageModel()
{ this.basicInfoModel = new basicInfoModel();}
}
RandomPage.cshtml
@using (Html.BeginForm())
{
@Html.Partial("_BasicInfoPartView ", @Model.BasicInfoModel)
@Html.TextBoxFor(m => m.info2)
...
<input type="submit" />
}
现在的问题: 我可以填充页面没有问题。 但是当我尝试从模型中检索控制器中的信息时: RandomPageModel.info2 OK! RandomPageModel.BasicInfoModel是空的...
我觉得我会错过了解数据绑定的概念:■ 我试试这个,因为我不想被小JS函数重载我的网页和不喜欢的想法牛逼复制过去我的形式(代码维护)。
提前致谢。
Cantinos。
您可以在编辑器模板的名称去掉 “_”,并使用@ Html.EditorFor(M => m.BasicInfoModel) – Dima 2013-03-12 17:05:24
@Dima +1编辑,以反映,谢谢 – 2013-03-12 17:07:45
这是一个我仍然需要学习的技巧 – 2013-03-12 17:08:27