私は以下のようなビューモデルを持っています。 ネストされたビューモデルでAllowOrgs
とIsOrgOnly
のプロパティ名/ EditAddressViewModel
も使用したいと思います。
この目的を達成する方法は?ネストしたビューモデルのメインビューモデルのプロパティ名と値を使用
私の主なビューは次のようになります -
@Html.EditorFor(m=> m.AddressEditor,"AddAddress")
私の主なビューモデルは、このようなものです -
public class AddressViewModel
{
public EditAddressViewModel AddressEditor {get; set;}
public bool AllowOrgs { get;set; }
public bool IsOrgOnly { get; set; }
}
あなたはビューモデルを持っているので、 'EditAddressViewModel'はこれらのプロパティを含むだけですが、[overloads](https://msdn.microsoft.com/en-us/library/)のいずれかを使って値を渡すことができます。 system.web.mvc.html.editorextensions.editorfor(v = 118).aspx#M:System.Web.Mvc.Html.EditorExtensions.EditorFor''2%28System.Web.Mvc.HtmlHelper {'' 0} 、AddViewDataを受け入れる 'EditorFor'のSystem.Linq.Expressions(System.Func {' '0、' 1}}、System.Object%29) '@ Html.EditorFor(m => m.AddressEditor、new {allowOrgs = Model.AllowOrgs})' –
'AdditonalViewData'はその場で設定することができますか、親ビューモデルのビューバッグに含める必要がありますか? – GilliVilla
'AllowOrgs'がモデルの一部である場合、' ViewBag'は必要ありません。そしてテンプレートでは、 'bool AllowOrgs = ViewData [" allowOrgs "];' –