自动完成 - 重新输入前几个字符后,如何触发数据源的服务器端绑定

时间:2017-12-09 17:42:32

标签: c# asp.net-mvc kendo-ui kendo-asp.net-mvc

我在自动完成小部件上使用Ajax绑定。绑定第一次工作正常(在第一次加载数据时),但是如果我备份该值,它将不会再次返回服务器(它不会刷新它的dataSource项)。如果输入新字符串,如何刷新dataSource?

@(Html.Kendo().AutoComplete()
    .Name("Orders")
    .HtmlAttributes(new { style = "background-color:lightyellow;width:300px;" })
    .Events(e =>
    {
        e.Select("selectOrder");
    })
    .Filter("startswith")
    .Placeholder("Select order or enter new one")
    .Filter("startswith")
    .MinLength(3)    
    .DataSource(dataSource => dataSource
    .Read(read => read.Action("CustomerOrders", "Processing")
    .Type(HttpVerbs.Post).Data("getInputs"))).DataTextField("HouseNo")) 

2 个答案:

答案 0 :(得分:1)

我认为您要将数据源上的ServerOperation设置为true,如下所示:

.DataSource(dataSource => dataSource
.Read(read => read.Action("CustomerOrders", "Processing"))
.ServerOperation(true)

答案 1 :(得分:1)

由于您提供了读取的输入文本,因此您必须将数据源的ServerFilteringdocumentation)设置为true,以便始终从服务器进行过滤。我猜这是你想要处理它的方式吗? 这将始终触发服务器过滤,但如果您有大量数据,那么为您的请求设置MinLength可能是个好主意,例如3-4这样

.MinLength(4)

这样,在输入前4个字符后,您的数据源将会读取,当您删除字符时,也会触发dataSource.Read。