簡體   English   中英

將控件綁定到EditorFor模板中的父模型

[英]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 &#187;</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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM