からのアクセスコンテナ:ASP.NET MVC:次のプロパティが含まれています、私はビューモデルに<strong>AssetFreezeViewModel.cs</strong>を持ってEditorTemplate
public AssetFreezeAccountBalanceViewModel AccountBalanceInfo { get; set; }
私が持つ上記のViewModelに基づいてDetails.cshtmlビューを持っていますその行:\ビューで
@Html.EditorFor(x => x.AccountBalanceInfo)
は\共有\ EditorTemplates \は、私はテンプレートAssetFreezeAccountBalanceViewModel.cshtml玉葉を持っています電子名がそのEditorTemplateでは(慣例により)AssetFreezeAccountBalanceViewModel
あるAccountBalanceInfoの型と同じです、私が持っている:
@Html.EditorFor(model => model.DeviseId)
でAssetFreezeAccountBalanceViewModel.csを、私が持っている:
[UIHint("DropDownList")]
public Int16? DeviseId { get; set; }
public IEnumerable<SelectListItem> DeviseIdList { get; set; }
最後に、\ Views \ Shared \ EditorTemplates \にDropDownList.cshtml(慣例によりDeviseIdに適用されます):
@model dynamic
@{
var propertyNameLookup = this.ViewData.ModelMetadata.PropertyName + "List";
var property = this.ViewData.ModelMetadata.Container.GetType().GetProperty(propertyNameLookup);
...
}
コードは、@ Html.EditorFor(モデル=> model.DeviseId)に当たるとコンテナが、その後クラッシュヌルであり、我々はDropDownList.cshtmlを入力してください。
ビューから2レベル下のEditorTemplateからContainer(= parent)にアクセスするにはどうすればよいですか?
AssetFreezeAccountBalanceViewModel.cshtmlの上部に@model AssetFreezeAccountBalanceViewModelがありますか? – onefootswill