[英]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.