我想添加如下的css类语句:
<%: Html.TextBoxFor(model => model.Comments, new { @class = "lookandfeel_1" })%>
到这一行:
<%: Html.TextBoxFor(model => model.Money, String.Format("{0:F}", Model.Money)) %>
我该怎么做?
答案 0 :(得分: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" }) %>
如果您使用的是Entity Framework或类似的,则需要执行以下操作来添加元数据属性:
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; }
}
}