[英]How format values in IEnumerable view model in ASP.NET Core MVC?
@Html.DisplayFor(modelItem => item.vouchertype == "P" ? "Paid" : "Receipt")
&
@Html.DisplayFor(modelItem => item.dated.ToString("dd-MMM-yy"))
Trying to format the value but error occurs: 尝试格式化值,但发生错误:
Template can use only with field access, property access, single dimension array index or single parameter custom indexer experssions.
模板只能与字段访问,属性访问,一维数组索引或单参数自定义索引器扩展一起使用。
I assume posted lines are part of forech
or other loop, and we speak about single item at that point. 我假设发布的行是
forech
或其他循环的一部分,并且在这一点上我们谈论单个项目。
In your Lambda expression you should use modelItem
variable instead on item
在Lambda表达式中,应在
item
上使用modelItem
变量
@Html.DisplayFor(modelItem => modelItem.vouchertype == "P" ? "Paid" : "Receipt")
&
@Html.DisplayFor(modelItem => modelItem.dated.ToString("dd-MMM-yy"))
In Lambda expression
rule is following: 在
Lambda expression
规则如下:
x => x become your variable
https://msdn.microsoft.com/en-us/library/bb397687.aspx https://msdn.microsoft.com/zh-CN/library/bb397687.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.