2010-11-15 58 views

回答

1

嘗試與顯示格式屬性裝飾的財產:

//Your view object 
[DisplayFormat(DataFormatString= "{0:F}")] 
public Double Money { get; set; } 

//Your view code 
<%: Html.TextBoxFor(model => model.Money, new { @class = "lookandfeel_1" }) %> 

如果您正在使用實體框架或類似的,你需要做以下的添加元數據屬性:

using System.ComponentModel.DataAnnotations; 

    namespace MyNameSpace 
    { 

     [MetadataType(typeof(MetaDataProduct))] 
     public partial class MyEntityClass 
     { 

     } 

     public class MetaDataProduct 
     {  
      [DisplayName("Price")] 
      [DisplayFormat(DataFormatString= "{0:F}")] 
      public int Money{ get; set; } 
     } 
    }