2013-04-04 40 views
-2

我想通过在属性中使用DisplayFormat属性在侧面文本框中显示百分比(%)符号。如何在侧面文本框中显示百分比(%)叹息

我使用MVC3

我的模型是

public class CommodityParticularInfo : EntityBase 
{ 
    private decimal? _standardReceived; 
    public decimal? StandardReceived 
    { 
     get { return _standardReceived; } 
     set { _standardReceived = value; } 
    } 
} 

观是

@Html.TextBoxFor(m => m.StandardReceived, new { @class = "textboxreadonly", @style = "width:100%", @ReadOnly = "ReadOnly" }) 

回答

0

尝试使用0'%'作为DisplayFormatString(单引号中的百分比),这应该有助于实现将百分号附加到您的数字。所以你得到33%。

你还可以尝试的另一件事可能是0%(不知道它是否会起作用),但应该按照你的意愿达到相同的33%。

Display format string, int to percent

+0

这是直接复制并从链接的问题贴。可能会更好地连接答案..完全信任作者。 – 2013-04-04 21:35:31

+0

@SimonWhitehead这就是为什么我把链接在那里 – Kyle 2013-04-08 21:47:10

0

尝试:

[DisplayFormat(DataFormatString = "{0:P2}")]  
public decimal? StandardReceived 
{ 
     get { return _standardReceived; } 
     set { _standardReceived = value; } 
}