为什么 Html.DisplayFor 显示模型 属性 名称而不是 属性 值?
Why does Html.DisplayFor show the model property name and not the property value?
我有以下 Razor table 列:
<td style="width: 300px;">@Html.DisplayFor(m => m.TendersReceived[i].Name)</td>
然而,该列的客户端再现显示模型 属性 name,即上面的名称列中显示 Name
,而不是真实姓名,值 Name
属性.
有关 TendersReceived
属性 的更多信息:
public List<TenSubTenderersQualitySummaryItemViewmodel> TendersReceived { get; set; } = new List<TenSubTenderersQualitySummaryItemViewmodel>();
public class TenSubTenderersQualitySummaryItemViewmodel
{
public int Number { get; set; }
public string Name { get; set; }
public decimal Wq { get; set; }
public decimal Threshold { get; set; }
[Display(Name = "Qualify")]
public bool DoesQualify { get; set; }
[Display(Name = "Qualify")]
public string DoesQualifyText => DoesQualify ? "YES" : "NO";
public string Progress { get; set; }
[Display(Name = "Staff Acceptability")]
public string StaffAcceptability { get; set; }
[Display(Name = "POINTS RANKING")]
public decimal PointsRanking { get; set; }
public bool IsNrt { get; set; }
public decimal PointsTechnical { get; set; }
public decimal PointsManagement { get; set; }
public decimal PointsQuality { get; set; }
public decimal PointsTotal { get; set; }
}
您对
的使用
DisplayFor<TModel,TValue>(HtmlHelper<TModel>, Expression<Func<TModel,TValue>>)
Returns HTML markup for each property in the object that is represented by the Expression expression.
不正确。它通常用于模板化,通常不将 DisplayFor
用于基本类型。
使用上面的方法会尝试将 属性 名称呈现为标签,然后呈现其值。
Name {value here}
如果值为 null 或空字符串,您只会看到标签。
假设集合是视图模型的成员,只需调用模型的成员
<td style="width: 300px;">@Model.TendersReceived[i].Name</td>
我有以下 Razor table 列:
<td style="width: 300px;">@Html.DisplayFor(m => m.TendersReceived[i].Name)</td>
然而,该列的客户端再现显示模型 属性 name,即上面的名称列中显示 Name
,而不是真实姓名,值 Name
属性.
有关 TendersReceived
属性 的更多信息:
public List<TenSubTenderersQualitySummaryItemViewmodel> TendersReceived { get; set; } = new List<TenSubTenderersQualitySummaryItemViewmodel>();
public class TenSubTenderersQualitySummaryItemViewmodel
{
public int Number { get; set; }
public string Name { get; set; }
public decimal Wq { get; set; }
public decimal Threshold { get; set; }
[Display(Name = "Qualify")]
public bool DoesQualify { get; set; }
[Display(Name = "Qualify")]
public string DoesQualifyText => DoesQualify ? "YES" : "NO";
public string Progress { get; set; }
[Display(Name = "Staff Acceptability")]
public string StaffAcceptability { get; set; }
[Display(Name = "POINTS RANKING")]
public decimal PointsRanking { get; set; }
public bool IsNrt { get; set; }
public decimal PointsTechnical { get; set; }
public decimal PointsManagement { get; set; }
public decimal PointsQuality { get; set; }
public decimal PointsTotal { get; set; }
}
您对
的使用DisplayFor<TModel,TValue>(HtmlHelper<TModel>, Expression<Func<TModel,TValue>>)
Returns HTML markup for each property in the object that is represented by the Expression expression.
不正确。它通常用于模板化,通常不将 DisplayFor
用于基本类型。
使用上面的方法会尝试将 属性 名称呈现为标签,然后呈现其值。
Name {value here}
如果值为 null 或空字符串,您只会看到标签。
假设集合是视图模型的成员,只需调用模型的成员
<td style="width: 300px;">@Model.TendersReceived[i].Name</td>