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