This is a migrated thread and some comments may be shown as answers.

Filter value is NULL

3 Answers 180 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Andre Damsteegt
Top achievements
Rank 1
Andre Damsteegt asked on 19 Jun 2013, 08:35 AM
Using the Kendo Autocomplete to search in a collection of 5000+ items stored in a database. Due to that is chosen to perform the filtering on the server. The problem is that the search value (parameter filter) received by the function is always NULL.

The project is MVC4/razor based, on the page the autocomplete is defined like this:

@(Html.Kendo().AutoComplete()
                  .Name(
"ExternalId")
                  .Placeholder(
"Search...")
                  .MinLength(3)
                  .DataSource(source => source.Read(read => read.Action(
"SourcesForAutoComplete", "Source")
    .Data(
"onAdditionalData"))
                  .ServerFiltering(
true))
                  .HtmlAttributes(
new { style = "width:468px" }))
The javascript handling the additional data events is placed at the end of the cshtml of the page:
<script>
    function onAdditionalData() {
        return { filter: $("#ExternalId").val() };
    }
</script>

The MVC Source controller has the following function to provide the data and search functionality:
public JsonResult SourcesForAutoComplete(string filter)
{
    using (var db = new EasyTaskIntegrationEntities())
    {
        ...
        return Json(result, JsonRequestBehavior.AllowGet);
    }
}
Can anyone explain why the filter value received is NULL instead of the value typed in the Autocomplete?

3 Answers, 1 is accepted

Sort by
0
Accepted
Andre Damsteegt
Top achievements
Rank 1
answered on 20 Jun 2013, 11:03 AM
It seems the filter value is not transmitted via the parameter of function.
The MVC Source controller has now the modified function to provide the data and search functionality: 
public JsonResult SourcesForAutoComplete()
{
    var searchValue = Request.Params["filter[filters][0][value]"];
    using (var db = new EasyTaskIntegrationEntities())
    {
       if (string.IsNullOrEmpty(searchValue)) searchValue = string.Empty;
       //Get max 20 results
       var result = db.Sources.Where(s => s.ExternalId.StartsWith(searchValue))
                                .OrderBy(s => s.ExternalId)
                                .Take(20)
                                .Select(s => s.ExternalId)
                                .ToArray();
 
       return Json(result, JsonRequestBehavior.AllowGet);
    }
}
0
Josh
Top achievements
Rank 2
answered on 25 Aug 2014, 05:52 PM
I'mhaving a hard time using your code for the autocomplete.   Will you post your controller and view code please?

Thanks!
0
kamlesh
Top achievements
Rank 1
answered on 02 Nov 2017, 05:10 AM

Its useful ..

Thank you..

Tags
AutoComplete
Asked by
Andre Damsteegt
Top achievements
Rank 1
Answers by
Andre Damsteegt
Top achievements
Rank 1
Josh
Top achievements
Rank 2
kamlesh
Top achievements
Rank 1
Share this question
or