AutoComplete with Server filtering in a Html Form Tag

4 posts, 1 answers
  1. STEPHAN
    STEPHAN avatar
    2 posts
    Member since:
    Sep 2011

    Posted 20 Jun Link to this post

    We have an Issue with the Server-side filtering feature from the kendoAutoComplete. This autocomplete is contained in a html form tag. When the request is performed on the asp.net mvc endpoint the DataSourceRequest is completly empty, becuase all the values for this object are in HttpContext.Request.Form, from where the DataSourceRequestAttribute doesn't parse it from. What should we do, to get the DataSourceRequest correctly bound?

    HTML Code

    <form class="navbar-form" role="search" method="post" action="@Url.Action("Results","Search")">

    // some other controls

    <div class="input-group">
    <span class="k-widget k-autocomplete k-header k-state-default myClass">
    <input type="text" id="autoCompleteSearch" name="autoCompleteSearch" class="form-control" />

    </span>
    <div class="input-group-btn">
    <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
    </div>
    </div>
    </form>

     

    JS Code:

    $('#autoCompleteSearch').kendoAutoComplete({
    minLength: 1,
    dataTextField: 'Caption',
    dataValueField: 'Value',
    filter: "contains",
    dataSource: {
    serverFiltering: true,
    transport: {
    read: {
    type: "post",
    dataType: "json",
    url: '@Url.Action("AdvancedSearchAutoComplete_Read", "AjaxValues")?searchType=' + window.searchType
    }
    },
    schema: {
    data: "Data"
    }
    }
    });

    Server-side:

    [System.Web.Mvc.HttpPost]
    public JsonResult AdvancesSearchAutoComplete_Read(int searchType, [DataSourceRequest] DataSourceRequest request)
    {

    //...

    }

     

    Thank you in advance!

  2. Peter Milchev
    Admin
    Peter Milchev avatar
    135 posts

    Posted 22 Jun Link to this post

    Hello Stephan,

    There is a typo in the Method's name and that may be the reason for the issue. Would you please renaming it from AdvancesSearchAutoComplete_Read to AdvancedSearchAutoComplete_Read and check if the problem persists?

    Regards,
    Peter Milchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. STEPHAN
    STEPHAN avatar
    2 posts
    Member since:
    Sep 2011

    Posted 23 Jun in reply to Peter Milchev Link to this post

    Hi Peter

    I saw the typo while posting the code fragments, which I've corrected in our sourcecode afterwards. This typo was not part of the Problem. The request is reaching the API Endpoint, but the [DataSourceRequest] DataSourceRequest request Parameter is empty (not null), because all relevant values are in HttpContext.Request.Form.

    How can I fix this Problem?

     

    Thank you in advance!

  5. Answer
    Peter Milchev
    Admin
    Peter Milchev avatar
    135 posts

    Posted 24 Jun Link to this post

    Hi Stephan,

    If you want to use DataSourceRequest and ToDataSourceResult instances you should set the DataSources' property type to "aspnetmvc-ajax". You can find an example in the documentation for Parameter Sending to Server. In your case the JavaScript code should look like the following:

    $('#autoCompleteSearch').kendoAutoComplete({
        minLength: 1,
        dataTextField: 'Caption',
        dataValueField: 'Value',
        filter: "contains",
        dataSource: {
            serverFiltering: true,
            type: "aspnetmvc-ajax",
            transport: {
                read: {
                    type: "post",
                    dataType: "json",
                    url: '@Url.Action("AdvancedSearchAutoComplete_Read", "AjaxValues")?searchType=' + window.searchType
                }
            },
            schema: {
                data: "Data"
            }
        }
    });


    Regards,
    Peter Milchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready