2013-04-04 110 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; } 
}