你试过用
@Html.TextBoxFor
帮手?
@model ConfiguracionModel // <-- obviously you need to bind your View to your model
@Html.TextBoxFor(m => m.ValorKilometro, "{0:n2}", new {
@class = "form-control",
@type = "number",
@min = "0" })
还可以将验证约束添加到模型中:
public class ConfiguracionModel
{
public Guid EmpresaGuid { get; set; }
public bool MaximoHabilitado { get; set; }
public int MontoMaximo { get; set; }
public Guid Moneda { get; set; }
[Range(0.0, double.MaxValue)]
[DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
public Double ValorKilometro { get; set; }
}
请注意
{0:n2}
表示两位小数。