【问题标题】:Kendo UI - Ajax MVC - JSON always nullKendo UI - Ajax MVC - JSON 始终为空
【发布时间】:2012-12-18 13:37:06
【问题描述】:

我有一个启用了排序功能的剑道网格。我想使用 jQuery 进行 ajax 回发,将排序信息发送到 action 方法以执行某些操作。

var datasource = $(".data-table").data("kendoGrid").dataSource;
$.ajax({
    type: 'POST',
    url: '@Url.Action("ExportToPDf", "MyController")',
    dataType: 'json',
    data: { sort: datasource._sort } 
});

我可以通过debugger 看到正确的值被获取并传入了 ajax 的 data 属性。我使用 FireBug 确认在 POST 操作期间传递了值。

public ActionResult ExportToPDf(List<SortDescription> sort)
{
    //Will be doing some action
    return null;
}

public class SortDescription
{   
    public string dir { get; set; }
    public string field { get; set; }
}

在 POST 操作期间来自 Firebug 的样本数据

sort[0][dir]    asc
sort[0][field]  EmployeeRef

当我在操作方法中保留断点时,我能够在列表中获取一项,但属性似乎为空。

谁能指导我做错了什么?

【问题讨论】:

    标签: asp.net-mvc json jquery kendo-ui


    【解决方案1】:

    试试这样的:

    $.ajax({
        url: '@Url.Action("ExportToPDf", "MyController")',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({sort: datasource._sort })
     })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-04
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      • 1970-01-01
      • 2020-05-22
      • 1970-01-01
      相关资源
      最近更新 更多