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

Autocomplete: Action Method always get null value

3 Answers 290 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
KIM
Top achievements
Rank 1
KIM asked on 27 Aug 2014, 02:31 AM
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);
}



3 Answers, 1 is accepted

Sort by
0
KIM
Top achievements
Rank 1
answered on 27 Aug 2014, 04:18 AM
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. 
0
KIM
Top achievements
Rank 1
answered on 27 Aug 2014, 04:22 AM
$('#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() }
            }
        }
    }
});
0
Daniel
Telerik team
answered on 28 Aug 2014, 02:32 PM
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.

 
Tags
AutoComplete
Asked by
KIM
Top achievements
Rank 1
Answers by
KIM
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or