gpt4 book ai didi

javascript - 字符串属性未反序列化

转载 作者:行者123 更新时间:2023-12-03 09:23:50 25 4
gpt4 key购买 nike

我不明白为什么只有字符串属性 Search.Value 在我的 ASP.NET MVC5 Controller 中没有被反序列化。请看这个:

客户端发送的Json结构:

{
"draw":1,
// ...
"start":0,
"length":50,
"search":{
"value":"This is always null in my controller",
"regex":false
}
}

我在服务器端的模型:

public class AsyncDataTableRequest
{
public int Draw { get; set; }
public int Start { get; set; }
public int Length { get; set; }
public Search Search { get; set; }
public string Value { get; set; }
}

public class Search
{
public string Value { get; set; }
public bool Regex { get; set; }
}

我想用 Search.Value 做一些事情的 Controller :

public JToken AsyncLogFetching(AsyncDataTableRequest req)
{
// req.Search.Value is null here, all other properties seem correct
...
}

感谢您的帮助!

编辑:对于“NewYork”的示例搜索,这是来自 IE 开发人员工具中“请求 header ”选项卡的请求:

GET /Log/AsyncLogFetching?draw=3&start=0&length=50&search%5Bvalue%5D=NewYork&search%5Bregex%5D=false&_=1438350434912 HTTP/1.1

IE 开发者工具中的“请求文本”选项卡显示“没有可显示的数据”。

这是执行 GET 请求的代码片段,它是从 jQuery DataTables Pipelining example 复制并粘贴的。 :

settings.jqXHR = $.ajax({
"type": conf.method, // GET
"url": conf.url,
"data": request,
"dataType": "json",
"contentType": "application/json",
"cache": false,
"success": function (json) {
// ...
}
});

最佳答案

尝试使用 JSON.stringify(yourObject) 将数据从客户端发送到 Controller

请引用以下内容 How to send nested json object to mvc controller using ajax

关于javascript - 字符串属性未反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747361/

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