Autocomplete: Action Method always get null value

4 posts, 0 answers
  1. KIM
    KIM avatar
    6 posts
    Member since:
    Jul 2014

    Posted 26 Aug 2014 Link to this post

    Hi Guys,

    I was trying to list of values from Action, but the action always get null value.

    my cshtml
    <div class="form-group">
        @Html.LabelFor(m => m.OrganizationName, new { @class = "col-md-4 control-label" })
        <div class="col-md-4">
            @Html.Kendo().AutoCompleteFor(m => m.OrganizationName)
    .MinLength(3).Name("OrganizationName")
    .DataSource(s => { s.Read(r => { r.Action("FindVets", "General"); }); })
    .DataTextField("Name")
    .HtmlAttributes(new { @class = "form-control" })
        </div>
    </div>


    Action :
    public JsonResult FindVets(string OrganizationName)
    {
        var Vets = General.GetRegularVet();
        var a = (from v in Vets
                 where v.Name.ToUpper().Contains(OrganizationName.ToUpper())
                 select v).ToList();
        return Json(a, JsonRequestBehavior.AllowGet);
    }



  2. KIM
    KIM avatar
    6 posts
    Member since:
    Jul 2014

    Posted 26 Aug 2014 in reply to KIM Link to this post

    I solved the issue below

          
    $('#OrganizationName').kendoAutoComplete({
        dataTextField: "Name",
        minLength: 3,
        type: "json",
        filter:"contains",
        dataSource: {
            serverFiltering: false,
            transport: {
                read:{
                    url: "@Url.Action("FindVets","General")",
                    dataType: "json",
                    data: { "OrganizationName": $('#OrganizationName').val() }
                }
            }
        }
    });

    I think the kendo html extender does not handle the Json format data. 
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. KIM
    KIM avatar
    6 posts
    Member since:
    Jul 2014

    Posted 26 Aug 2014 in reply to KIM Link to this post

    $('#OrganizationName').kendoAutoComplete({
        dataTextField: "Name",
        minLength: 3,
        type: "POST",
        filter:"contains",
        dataSource: {
            serverFiltering: false,
            transport: {
                read:{
                    url: "@Url.Action("FindVets","General")",
                    dataType: "json",
                    data: { "OrganizationName": $('#OrganizationName').val() }
                }
            }
        }
    });
  5. Daniel
    Admin
    Daniel avatar
    2118 posts

    Posted 28 Aug 2014 Link to this post

    Hello,

    The wrapper dataSource can also be configured to filter the data on the server by using the ServerFiltering method:
    .DataSource(s =>
    {
          s.Read(r =>
          {
              r.Action("FindVets", "General");
          });
          s.ServerFiltering(true);
    })

    To pass the text in this case you can use the data function:
    .DataSource(s =>
    {
        s.Read(r =>
        {
            r.Action("FindVets", "General").Data("additionalData");
        });
        s.ServerFiltering(true);
    })
    function additionalData() {
        return {
            OrganizationName: $("#OrganizationName").val()
        };
    }


    Regards,
    Daniel
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready