0
我有以下问题在视图中显示的钱
public decimal? Price {get;set;}
当我到文本框上输入视图3000.00(下面的文本框)
<div class="form-group">
<label class="col-lg-3 control-label no-padding-right">Price</label>
<div class="col-lg-5">
@Html.ValidationMessageFor(m => m.Price)
<div class="input-group">
<span class="input-group-addon">£</span>
@Html.TextBoxFor(m => m.Price, new { @class = "form-control", type = "text", id = "txtPrice", onkeypress = "return isNumberKey(event)" })
</div>
</div>
<label class="col-lg-4 control-label" style="text-align: left">Decimal format</label>
所以它看起来像此
它在数据库中保存为3000.00预计,但是当我返回到视图来编辑它在文本框中的值是3000.0000
我已经尝试了一些解决方案,在这里
Remove trailing zeros of decimal
我想我的问题是在视场为十进制类型不是字符串的,所以我对如何,所以它看起来像上面的图片
使用接受的格式字符串'@ Html.TextBoxFor(M => m.Price, “{0:0.00}”,新的{....})过载' – 2015-02-08 02:36:32