角度剑道网格过滤器和排序信息击中MVC控制器时丢失

时间:2017-05-01 15:40:26

标签: angularjs asp.net-mvc kendo-grid

我在获取过滤器并将信息从Kendo Grid排序到我的MVC控制器时遇到问题。我正在使用服务将表单数据和DataSource数据传递给MVC控制器。

这是我的Kendo Grid DataSource:

dataSource: new kendo.data.DataSource({
          transport: {
              read: function (e) {
                  generalsearchService.submitSearch(e.data, form)
                      .then(function success(response) {
                          e.success(response.data);
                      });
              }
          },
          schema: {
              data: "Data",
              total: "Total"
          },
          pageSize: 25,
          serverPaging: true,
          serverFiltering: true,
          serverSorting: true

      }),

以下是我服务中的代码:

  this.submitSearch = function (command, form) {
return $http.post('/SSQV4/SSQV5/Search/SubmitCriteria', {'command': command, 'form': form});

};

这是我的MVC控制器方法定义:

public async Task<ActionResult> SubmitCriteria(DataSourceRequest command, ContractorSearchViewModel form)

当它到达dataSource时,过滤器信息就在那里:

enter image description here

当它到达服务时,过滤器信息就在那里:

enter image description here

当它击中MVC控制器时它就消失了:

enter image description here

我尝试包含'type:“aspnetmvc-ajax”',但它会抛出此错误:

enter image description here 非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

必须手动将aspnetmvc-server“注入”到传输中才能使其正常工作。这是修复:

在Angularjs控制器中:

var form = $scope.form;
dataSource: new kendo.data.DataSource({
          transport: {
              read: function (e) {
                  var grid = $scope.SearchGrid;
                  var requestObject = (new kendo.data.transports["aspnetmvc-server"]({ prefix: "" }))
                      .options.parameterMap({
                          page: grid.dataSource.page(),
                          sort: grid.dataSource.sort(),
                          filter: grid.dataSource.filter(),
                          pagesize: grid.dataSource.pageSize()

              });
                  generalsearchService.submitSearch({ page: requestObject.page, sort: requestObject.sort, filter: requestObject.filter, pagesize: requestObject.pagesize, form: form })
                      .then(function success(response) {
                          e.success(response.data);
                      });
                }
            },
              schema: {
                  data: "Data",
                  total: "Total"
              },
          pageSize: 25,
          serverPaging: true,
          serverFiltering: true,
          serverSorting: true

在Angularjs服务中:

  this.submitSearch = function (form) {
return $http.post('/SSQV4/SSQV5/Search/SubmitCriteria', form );

};

在MVC控制器中:

        public async Task<ActionResult> SubmitCriteria([DataSourceRequest] DataSourceRequest request, ContractorSearchViewModel form)

一切正常运作。希望这有助于其他人。快乐的编码!