I am currently trying to get a kendo ui autocomplete to show results even if a user enters first and second name. At the moment i currently have my code working if the autocomplete contains first or second name. I would like the autocomplete to still show results for e.g if 'Peter S' was entered it would still show a results for 'Peter Smith' and 'Peter Samsung'. If someone could have a look at my code and maybe point me in the correct direction that would be great. I have spent alot of time on this and i think i might be taking the wrong approach.
Code below:
$("#FeeEarnerEmailSend").kendoAutoComplete({
dataSource: new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: "/" + prefix + "/api/Session/GetEmployees",
parameterMap: function () {
return { id: $("#FeeEarnerEmailSend").data("kendoAutoComplete").value() };
}
}
}),
dataTextField: 'FullName',
filter: "contains",
//placeholder: "Search...",
minLength: 3,
suggest: true,
select: function (e) {
var employeeAutoComplete = e.sender;
// this var is used in the Search button click event
selectedEmployeeDataItem = employeeAutoComplete.dataItem(e.item.index());
},
change: function () {
if ($.trim($("#FeeEarnerEmailSend").val()) == "") {
selectedEmployeeDataItem = null;
}
},
dataBound: function (e) {
selectedEmployeeDataItem = e.sender.dataItem(0);
}
});
This is my Csharp code, i think the issue may lie here within my linq which needs edited to achieve this?
[HttpGet]
[Route("api/Session/GetEmployees")]
public IHttpActionResult GetEmployees(string id)
{
logger.Trace("Get Employees - {0} - based on prefix", id);
try
{
DirectoryContext context = new DirectoryContext(new Uri(ConfigurationManager.AppSettings["DirectoryServiceUrl"]));
var result = from q in context.Employees
where q.Surname.Contains(id) || q.KnownAs.Contains(id)
orderby q.Surname, q.KnownAs
select new
{
NetworkId = q.NetworkID,
FullName = String.Format("{0} {1}", q.Surname.ToUpper(), q.KnownAs),
EmailAddress = q.EmailAddress
};
logger.Info("Returning Employees - {0}", id);
return Ok(result.ToList());
}
catch (Exception ex)
{
logger.Error(ex.Message, ex);
return InternalServerError(ex);
}
}