繁体   English   中英

MVC @ Html.DisplayFor-分配DisplayTemplate

[英]MVC @Html.DisplayFor - Assigning the DisplayTemplate

我有一个视图模型OrderViewModel ,上面有一个类“ CustomerViewModel

我想这样显示:

 @Html.DisplayFor(x=>x.CustomerViewModel)

如何为CustomerViewModel类赋予属性,以便MVC使用以下方法呈现它:

/Views/Shared/DisplayTemplates/MyUIForCustomerViewModel.cshtml 

CustomViewModel的属性上使用UIHint属性

[UIHint("MyUIForCustomerViewModel")]
public CustomViewModel CustomViewModel { get; set; }

或者,您可以将显示模板的名称与类名称相同:

 /Views/Shared/DisplayTemplates/CustomerViewModel.cshml

您还可以将模板名称传递给Html.DisplayFor helper

@Html.DisplayFor(x=>x.CustomerViewModel, "MyUIForCustomerViewModel")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM