格式化小数在视图中

编程入门 行业动态 更新时间:2024-10-15 08:27:10
本文介绍了格式化小数在视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我有一个字段的十进制值,我想在页面上显示,我怎么格式化(我会使用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)

更多推荐

格式化小数在视图中

本文发布于:2023-07-07 04:20:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小数   视图

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!