gpt4 book ai didi

c# - ASP.NET MVC 后序列化与数据输入不匹配

转载 作者:行者123 更新时间:2023-11-30 12:28:38 24 4
gpt4 key购买 nike

请求

POST http://localhost:51446/Home/AddUserToGroup HTTP/1.1
Host: localhost:51446
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:51446/Home/ViewFriends
Content-Length: 41
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

userId=24401403&groupId=10100745654968505

回应

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 5.0
X-AspNet-Version: 4.0.30319
Date: Sat, 11 Jan 2014 22:54:19 GMT
Content-Length: 47

{"groupId":10100745654968504,"userId":24401403}

Controller Action

public ActionResult AddUserToGroup(AddUserVM vm)
{
return Json(vm);
}

查看模型

public class AddUserVM
{
public double groupId { get; set; }
public double userId { get; set; }
}

输入 10100745654968505 输出 10100745654968504

最佳答案

都与 float 的内部表示和精度有关。看到这个例如,http://en.wikipedia.org/wiki/Double-precision_floating-point_format .

将 double 更改为小数应该可以使您的代码正常工作。

来自 Jon Skeet 的更详细解释:https://stackoverflow.com/a/618596/932418

关于c# - ASP.NET MVC 后序列化与数据输入不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21069003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com