发布一个模型剑道电网读取动作剑道、电网、模型、动作

2023-09-06 14:57:24 作者:伪装的坚强i

我想添加一个搜索表单我的页面更新剑道网格。我应该如何发送Ajax调用,所以ASP.NET MVC模型绑定能工作吗?

I'm trying to add a search form to my page that updates the Kendo Grid. How should I send the Ajax call, so the ASP.NET MVC Model Binder be able to work?

这是我的Ajax调用:

This is my Ajax call:

var grid = $("#SearchSheetHeads").data('kendoGrid');
var data = $("#SearchSheet").serialize();
grid.dataSource.transport.options.read.url = "@Url.Action("SearchHeaderRead", "Sheet")";
grid.dataSource.transport.options.read.data = data;
grid.dataSource.transport.options.read.dataType = 'json';
grid.dataSource.transport.options.read.contentType = "application/json";
grid.dataSource.transport.options.read.type = "POST";
grid.dataSource.fetch();

我也尝试过通过字符串化方法和删除的contentType

这是我行动的签名:

public ActionResult SearchHeaderRead([DataSourceRequest] DataSourceRequest request, SearchSheetHeaderViewModel model)

和的要求是这样的:

推荐答案

目前无法测试,但尝试是这样的:

Can't test it at the moment, but try something like this:

var grid = $("#SearchSheetHeads").data('kendoGrid');
var data = $("#SearchSheet").serialize();
$.ajax(
{
    type: 'POST',
    url: '@Url.Action("SearchHeaderRead", "Sheet")',
    dataType: 'json',
    data: { model: data },
    success: function (result) {
        grid.dataSource.data(result.Data);
    }
});

数据:{模型:数据} 可能是你的重要组成部分。

data: { model: data } is probably the important part for you.