I have the following .chtml, view model, and controller actions. However, the auto complete never displays any results even though I can see that the Jason results are sent back to the browser.
.chtml
@model IEnumerable<Trishulla.Erp.Web.Core.Main.Models.CustomerNameModel>
@{
ViewBag.Title = "New Appointment";
}
<section class="contentTile">
New Appointment
</section>
@section navigation{
@Html.Partial("_DailyServiceLeftNav")
}
@(Html.Kendo().AutoComplete()
.Name("CustomersAutoComplete")
.BindTo(Model)
.Suggest(true)
.DataTextField("Name")
.Filter(FilterType.StartsWith)
.Placeholder("Customers...")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetActiveCustomers", "DailyService");
}).ServerFiltering(true);
})
)
View Model:
public class CustomerNameModel
{
public int Id { get; set; }
public string Name { get; set; }
}
Controller actions:
public ActionResult NewAppointment()
{
IEnumerable<CustomerNameModel> customerModel = this.customerService.CustomerRepository.GetMany(c => c.IsActive)
.Select(c => new CustomerNameModel
{
Id = c.Id,
Name = string.Format("{0} {1}", c.FirstName, c.LastName)
});
return View(customerModel.ToList());
}
[HttpGet]
public ActionResult GetActiveCustomers([DataSourceRequest] DataSourceRequest request)
{
string searchValue = Request.Params["filter[filters][0][value]"];
IEnumerable<CustomerNameModel> customerModel = this.customerService.CustomerRepository.GetMany(c => c.IsActive)
.Select(c => new CustomerNameModel
{
Id = c.Id,
Name = string.Format("{0} {1}", c.FirstName, c.LastName)
});
var returnVal = Json(customerModel.Where(c => c.Name.StartsWith(searchValue, StringComparison.InvariantCultureIgnoreCase)).ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
return returnVal;
}
.chtml
@model IEnumerable<Trishulla.Erp.Web.Core.Main.Models.CustomerNameModel>
@{
ViewBag.Title = "New Appointment";
}
<section class="contentTile">
New Appointment
</section>
@section navigation{
@Html.Partial("_DailyServiceLeftNav")
}
@(Html.Kendo().AutoComplete()
.Name("CustomersAutoComplete")
.BindTo(Model)
.Suggest(true)
.DataTextField("Name")
.Filter(FilterType.StartsWith)
.Placeholder("Customers...")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetActiveCustomers", "DailyService");
}).ServerFiltering(true);
})
)
View Model:
public class CustomerNameModel
{
public int Id { get; set; }
public string Name { get; set; }
}
Controller actions:
public ActionResult NewAppointment()
{
IEnumerable<CustomerNameModel> customerModel = this.customerService.CustomerRepository.GetMany(c => c.IsActive)
.Select(c => new CustomerNameModel
{
Id = c.Id,
Name = string.Format("{0} {1}", c.FirstName, c.LastName)
});
return View(customerModel.ToList());
}
[HttpGet]
public ActionResult GetActiveCustomers([DataSourceRequest] DataSourceRequest request)
{
string searchValue = Request.Params["filter[filters][0][value]"];
IEnumerable<CustomerNameModel> customerModel = this.customerService.CustomerRepository.GetMany(c => c.IsActive)
.Select(c => new CustomerNameModel
{
Id = c.Id,
Name = string.Format("{0} {1}", c.FirstName, c.LastName)
});
var returnVal = Json(customerModel.Where(c => c.Name.StartsWith(searchValue, StringComparison.InvariantCultureIgnoreCase)).ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
return returnVal;
}