千位分隔符十进制值在控制器端转换为0 [英] Thousand separator decimal value converted to 0 at controller end

查看:83
本文介绍了千位分隔符十进制值在控制器端转换为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们最近使用.Net Framework 4.6.1,MVC 5.2.3和EF 6升级了我们的应用程序。



我们使用小数值来保持模型级别的总格式和给定格式如下所示



Hi,

We have recently upgraded our application with .Net Framework 4.6.1, MVC 5.2.3 and EF 6.

We have used decimal values to hold total and given format at model level as below

[DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
        public decimal totalSale { get; set; }





现在来自View我使用JS函数提交数据如下





Now from View I am submitting data using JS function as below

$.ajax({
            type: "POST",
            url: "Home/SaveHeader",
            data: $("form").serialize(),
            success: function (result)





因此,这个序列化会产生问题,而totalsale值为> = 1000 - 因为它增加了千位分隔符(1,000)。在控制器端totalsale显示零值。



我们检查了旧版本,这个功能运行正常。



因此,任何关于我们在这里缺少的信息,或者可能是什么原因和替代方法来解决这个问题都会有所帮助。



提前致谢。



我尝试过:



我们尝试在序列化之前删除JS中的千位分隔符(,),在这种情况下它工作正常。



So this serialization creates problem while "totalsale" value is >= 1000 - as it is adding thousand separator (1,000). At the controller end "totalsale" shows zero value.

We checked in old version and this functionality was working fine.

So any clue on what we are missing here or what could be the reason and\or alternate to fix this will be helpful.

Thanks in advance.

What I have tried:

We tried removing thousand separator (,) in JS before serialization, in that case it is working fine.

推荐答案

.ajax({
type: POST
url: Home / SaveHeader
data:
.ajax({ type: "POST", url: "Home/SaveHeader", data:


form)。serialize(),
success: function (result)
("form").serialize(), success: function (result)





因此,当totalsale值为> = 1000时,此序列化会产生问题 - 因为它会增加千位分隔符(1,000)。在控制器端totalsale显示零值。



我们检查旧版本,此功能正常。



因此,任何关于我们在这里缺少的信息,或者可能是什么原因和替代方法来解决这个问题都会有所帮助。



提前致谢。



我的尝试:



我们尝试在序列化之前删除JS中的千位分隔符(,),在这种情况下它工作正常。



So this serialization creates problem while "totalsale" value is >= 1000 - as it is adding thousand separator (1,000). At the controller end "totalsale" shows zero value.

We checked in old version and this functionality was working fine.

So any clue on what we are missing here or what could be the reason and\or alternate to fix this will be helpful.

Thanks in advance.

What I have tried:

We tried removing thousand separator (,) in JS before serialization, in that case it is working fine.


这篇关于千位分隔符十进制值在控制器端转换为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆