-1

我在部分视图中有 TextboxFor,我想显示十进制格式示例(3,108,000.00)。用于显示但希望我通过 Ajax 调用控制器的值为空。感谢您的帮助。

@Html.TextBoxFor(x => x.List_TRNQuotationLeasing.CashBook, new { @class = "numeric form-control right", @Value = Model.List_TRNQuotationLeasing.CashBook != null ? Model.List_TRNQuotationLeasing.CashBook.Value.ToString("#,##0.00") : "" })

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

如果您尝试这样做,则不能900,000.00直接将值发布到 。decimal您需要,在发送前重新格式化数字并删除,string在 ViewModel 中使用并在发布后应用转换,或者在请求期间使用特殊的 ASP.NET MVC Model Binder 进行转换。

例如,如果您想使用选项 1,您可以在发送 (jQuery) 之前在 JavaScript 中执行此操作:

 // ...before send...
 // e.g. apply to all fields marked with "numeric"
 $("input.numeric").each(function() {
    numericWithOutComma = $(this).val().replace(",", "");

    // override text... yes it will lose the format. You could enhance that later
    $(this).val(numericWithOutComma);
 });

 // Execute Ajax send...

此外,例如,如果您想使用选项 3,还有一个有趣的讨论。

于 2018-02-09T08:43:26.473 回答