I've been following this Kendo UI tutorial: Server filtering in ASP.NET Core AutoComplete Component Demo | Telerik UI for ASP.NET Core
But although I've made the changes I believe need to be to accommodate our data, no textbox for the user to type ahead into appears. Then looking at the code and especially at the model class, I realized that the field I'm trying to bind to the dataTextField property of kendo-autocomplete, is a nullable string. I'm wondering if that is what's causing the problems I'm experiencing? Here's some code snippets from my MVC view:
<div class="demo-section k-content">
<h5>Find a location</h5>
<kendo-autocomplete name="locations" style="width:100%"
dataTextField="LocationCode"
filter="contains"
min-length="2">
<datasource type="DataSourceTagHelperType.Custom" server-filter="true">
<transport>
<read url="@Url.Action("GetLocationByLocationCode", "SiteToSite")" data="onAdditionalData" />
</transport>
</datasource>
</kendo-autocomplete>
<div class="demo-hint">Hint: type "ca"</div>
<script>
function onAdditionalData() {
return {
text: $("#locations").val()
};
}
</script>
</div>
Here's the Index action method from the controller:
public async Task<IActionResult> Index()
{
BuildSelectLists();
SiteToSite siteToSite = new SiteToSite();
return View(siteToSite);
}
public void BuildSelectLists()
{
ViewData["EmployeeList"] = new SelectList(db.PharmEmployees.Where(x => x.ActiveYn == true).OrderBy(y => y.EmployeeName).ToList(), "EmployeeId", "EmployeeName");
}
And finally here's a snippet of the PharmLocation model class, which includes LocationCode (which is the nullable string I'm binding the dataTextField to:
public partial class PharmLocation
{
public PharmLocation()
{
PharmItemsReturnedExpiredFromLocs = new HashSet<PharmItemsReturnedExpiredFromLoc>();
PharmLocation340BRegistrations = new HashSet<PharmLocation340BRegistration>();
PharmLocationPaprogContracts = new HashSet<PharmLocationPaprogContract>();
}
public int LocationId { get; set; }
public bool? ActiveYn { get; set; }
public string? LocationCode { get; set; }
public string? LocationType { get; set; }
public string? Location { get; set; }