Querystring中的Kendo自动完成空过滤器 - serverfiltering

时间:2015-10-28 08:18:27

标签: asp.net asp.net-mvc autocomplete kendo-ui asp.net-core-mvc

我试图在Kendo UI中使用serverfiltering进行自动完成(ASP.NET 5,MVC6) 由于MVC Wrapper中无法使用自动完成功能,因此我必须使用以下代码:

<script>
    var dataSource = new kendo.data.DataSource({
        serverFiltering: true,
        serverOperation: true,
        type: "aspnetmvc-ajax",
        transport: {
            read: {
                url: "@Url.Content("~/api/Get")",
                type: "GET"
            }
        },
        schema: {
            data: "Data",
            total: "Total"
        }
    })

    $("#@Model.Name").kendoAutoComplete({
        placeholder: "@Model.Watermark",
        minLength: 3,
        filter: "contains",
        dataSource: dataSource

    });
</script>

问题是发送到控制器的查询字符串如下所示: ?排序=安培;组=安培;过滤器=

因此它不包含任何过滤器信息

在服务器端尝试将其映射到DataSourceRequest

1 个答案:

答案 0 :(得分:1)

现在我使用以下解决方法传递其他参数来执行serversidefiltering但我仍然想使用kendo native过滤:

<script>
    var dataSource = new kendo.data.DataSource({
        serverFiltering: true,
        serverOperation: true,
        type: "aspnetmvc-ajax",
        transport: {
            read: {
                url: "@Url.Content("~/api/Get")",
                type: "GET",
                data: onAdditionalData
            }
        },
        schema: {
            data: "Data",
            total: "Total"
        }
    })


    $("#@Model.Name").kendoAutoComplete({
        placeholder: "@Model.Watermark",
        minLength: 3,
        filter: "contains",
        dataSource: dataSource

    });

    function onAdditionalData() {
        return {
            text: $("#@Model.Name").val()
        };
    }
 </script>

控制器代码:

    [Route("api/Get")]
    [HttpGet]
    public JsonResult Get([DataSourceRequest] DataSourceRequest request, string text = "")
    {
        var list = (new List<string>() { "value1", "value2", "value3", "test" } ).AsQueryable();
        return Json(list.Where(x => x.Contains(text)).ToDataSourceResult(request));
    }