@ Html.DisplayNameFor详情模式 [英] @Html.DisplayNameFor for details model

查看:809
本文介绍了@ Html.DisplayNameFor详情模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的模型我有一个实体

In my model I have an Entity

public class Carrier
{
public Guid CarrierId { get; set; }
public string Name { get; set; }
}

我也有一个视图模型

I also have a ViewModel

public class CarrierIndexViewModel
{
public IEnumerable<Carrier> Carriers { get; set; }
public PagingInfo PagingInfo { get; set; }
}

我有一个强类型(CarrierIndexViewModel)索引视图,这是假设来显示使用PagingInfo载波表。

I have a strongly-typed (CarrierIndexViewModel) Index View, which is suppose to display a table of Carrier using PagingInfo.

我试图使用HTML帮助我的表的页眉中显示Carrier.Name
当我用了IEnumerable作为模型对这一观点我有
@ Html.DisplayFor(型号=&GT; model.Name)

I'm trying to use Html helper to display Carrier.Name in my table's header When I used IEnumerable as a model for this view I had @Html.DisplayFor(model => model.Name)

我如何用我的新CarrierIndexViewModel,显示Carrier.Name冠军得到同样的结果?

How can I get same result using my new CarrierIndexViewModel to display title for Carrier.Name?

推荐答案

您可以添加@using语句将查看到指定运营商的类型,那么你就需要通过模型的运营商属性循环。

You can add a @using statement to your View to specify the Carrier type, then you will need to loop through your Model's Carriers property.

您查看看起来像..

@model CarrierIndexViewModel
@using Carrier

@foreach(Carrier c in Model.Carriers)
{
 @Html.DisplayFor(model => c.Name)
}

这篇关于@ Html.DisplayNameFor详情模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆