字符串属性未反序列化

时间:2015-07-31 13:27:45

标签: javascript c# asp.net json

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

客户发送的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执行某些操作的控制器:

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

感谢您的帮助!

修改 对于使用" NewYork"进行的示例搜索,来自标签"请求标题"的请求在IE Developer工具中:

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

标签"请求文字"在IE开发人员工具中说"没有要显示的数据"。

这是执行GET-Request的代码片段,它是副本&粘贴自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) {
        // ...
    }
});

1 个答案:

答案 0 :(得分:1)

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

请参考以下内容 How to send nested json object to mvc controller using ajax