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

标签 javascript c# asp.net json

我不明白为什么只有字符串属性 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/

相关文章:

javascript - 如何从 Javascript 调用 C# 函数

asp.net - 如何获得两个 SSL 证书以在两个域共享 IP 配置上工作

javascript - 隐藏 css 溢出以显示定义的 "window"div 内的图像

javascript - 我在 data 属性中有一个变量,并从 prop 传递相同的变量。为什么 {{}} 模板显示 prop 中的值而不是 data

c# - 如何在不在服务器上安装 SSIS 的情况下在 C# 应用程序中使用 SSIS 包,这可能吗?

c# - IE9 中没有设置 Cookie

jQuery Full Calendar - 如何防止用户在非工作时间添加事件?

javascript - 动态模块加载在 Firefox 上不起作用 - SyntaxError : dynamic module import is not implemented

javascript - Aurelia 从动态添加的元素中删除EventListener

c# - SQLCLR 和 DateTime2