本文介绍了格式化小数在视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个字段的十进制值,我想在页面上显示,我怎么格式化(我会使用Web表单中的String.Format):
If I have a decimal value in a field, and I am trying to display on a page, how do I format it (I would use string.format in web forms):
@Html.DisplayFor(Function(modelItem) String.Format("{0:n0}",currentItem.QualityM1))这是错误与messae VS2010:模板只能与现场访问,访问属性,一维数组的索引,或单参数自定义索引前pressions使用
That errors in VS2010 with the messae: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
推荐答案我不会做这个视图中。这将是更好地集中这一点,并提供此信息作为元数据如下:
I wouldn't do this inside the view. It would be better to centralize this and provide this information as metadata as below:
public class Foo { [DisplayFormat(DataFormatString = "{0:n0}")] public decimal Bar { get; set; } }然后用这个像往常一样:
Then use this as usual:
@Html.DisplayFor(m => m.Bar)更多推荐
格式化小数在视图中
发布评论