![](/img/trans.png)
[英]MVC modal with partial view not prepoulating EditorFor control with model binding
[英]binding a control to parent model in EditorFor template
情况如下:我有一个绑定到父模型的视图。 在此视图中,我正在调用EditorFor并传递子对象。 但是在那个EditorFor中,我想绑定父模型的控件。 我该怎么做? 我还需要绑定验证控件。 我在父模型中创建了该属性。
@model ParentModel
//Parent view
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.EditorFor(m => m.Entity, new { CountiesServed = Model.CountiesServed, Types = Model.EntityTypes, CommunicationMethods = Model.CommunicationMethods, OrganizationTypes = Model.OrganizationTypes })
<p class="form-actions" style="text-align:right;">
<button type="submit" >Next »</button>
</p>
}
在子视图中-我不想将控件绑定到其视图模型,而是绑定到父视图//模型。 @model ChildModel
@Html.EditorFor(m=>m.somechildentityproperty)
//But how to do something like this?
@Html.EditorFor(//ParentModel property) ???
如果EditorFor
并未使用其作为Model的属性,那么这是一个警告标志,它实际上应该是Partial View,而不是 EditorFor
。 这样,您可以轻松传递父模型。
否则,保持一个EditorFor
你必须把父模型对孩子的财产,这是混乱的 ,至少可以说。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.