简体   繁体   English

NET的Kendo Ajax网格参数

[英]Kendo Ajax Grid Parameters with .Net

I have a Kendo grid in which I am trying to send additional data as a bool which I can use to filter the return data in my controller. 我有一个Kendo网格,我试图在其中发送其他数据作为布尔值,可以用来过滤控制器中的返回数据。

Controller: 控制器:

public ActionResult Securities_Read([DataSourceRequest]DataSourceRequest request, bool filter) {
    if (filter == true) // do something.
}

Read: 读:

.Read(read => read.Action("Action", "Controller").Data("filterFunction"))

filter Function: 过滤功能:

function filterFunction() {
    var filter = ($('#checkbox').is(":checked")) ? true : false;
    console.log(filter);
    return {
        filter: filter
    }
}

Checkbox event handler: 复选框事件处理程序:

$('#checkbox').change(function () {
    $('#grid').data('kendoGrid').dataSource.read();
});

Any time the checkbox is changed it runs the change function which in turn calls the kendo grid to run the read function. 每次更改复选框时,它都会运行change函数,后者依次调用kendo网格以运行read函数。 The kendo grid also calls the filterFunction to get additional parameters. kendo网格还调用filterFunction以获取其他参数。 I can see that the filterFunction is indeed being called because a log the value of filter to the console. 我可以看到filterFunction确实在被调用,因为将filter的值记录到控制台。 However once it gets back to the controller the value of the additional parameter is always null. 但是,一旦返回到控制器,附加参数的值将始终为空。

What am I missing? 我想念什么?

It seem that filter is a key word use in the kendo framework. 过滤器似乎是kendo框架中的关键词。 So when I changed: 所以当我改变时:

function filterFunction() {
    var filter = ($('#checkbox').is(":checked")) ? true : false;
    console.log(filter);
    return {
        filter: filter
    }
}

to: 至:

function filterFunction() {
    var filter = ($('#checkbox').is(":checked")) ? "true" : "false";
    console.log(filter);
    return {
        shouldFilter: filter
    }
}

Also notice that you can only pass strings as parameters so I had to change the parameter in the controller to a string and the true/false value to strings in the JavaScript function above: 还要注意,您只能将字符串作为参数传递,因此在上面的JavaScript函数中,我不得不将控制器中的参数更改为字符串,并将true / false值更改为字符串:

public ActionResult Securities_Read([DataSourceRequest]DataSourceRequest request, bool filter) {
    if (filter == true) // do something.
}

to: 至:

public ActionResult Securities_Read([DataSourceRequest]DataSourceRequest request, string filter) {
    if (filter == "true") // do something.
}

That solved my problem. 那解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM