[英]decimal format string is null in controller mvc razor c#
我在局部视图中有 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") : "" })
如果您尝试这样做,则不能将900,000.00
类的值直接发布到decimal
。 您需要重新格式化数字并删除,
在发送之前,在 ViewModel 中使用string
并在发布后应用转换,或者使用特殊的 ASP.NET MVC 模型绑定器在请求期间进行转换。
例如,如果您想使用选项 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,还有一个有趣的讨论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.