C# MVC@Html.DisplayFor-分配显示模板

C# MVC@Html.DisplayFor-分配显示模板,c#,asp.net,asp.net-mvc,visual-studio,C#,Asp.net,Asp.net Mvc,Visual Studio,我有一个视图模型OrderViewModel,上面有一个类,“CustomerViewModel” 我想这样展示它: @Html.DisplayFor(x=>x.CustomerViewModel) 如何赋予CustomerServiceWModel类属性,以便MVC使用以下内容呈现它: /Views/Shared/DisplayTemplates/MyUIForCustomerViewModel.cshtml 对CustomViewModel使用属性上的属性 [UIHint("M

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

我想这样展示它:

 @Html.DisplayFor(x=>x.CustomerViewModel)
如何赋予CustomerServiceWModel类属性,以便MVC使用以下内容呈现它:

/Views/Shared/DisplayTemplates/MyUIForCustomerViewModel.cshtml 
对CustomViewModel使用属性上的属性

[UIHint("MyUIForCustomerViewModel")]
public CustomViewModel CustomViewModel { get; set; }
或者,您可以将显示tamplate命名为与类名相同的名称:

 /Views/Shared/DisplayTemplates/CustomerViewModel.cshml
还可以将模板名称传递给帮助器

对CustomViewModel使用属性上的属性

[UIHint("MyUIForCustomerViewModel")]
public CustomViewModel CustomViewModel { get; set; }
或者,您可以将显示tamplate命名为与类名相同的名称:

 /Views/Shared/DisplayTemplates/CustomerViewModel.cshml
还可以将模板名称传递给帮助器