Reputation: 1617
I'm trying to configure kendo autocomplete using their tutorial. The problem is that autocomplete control display objects instead of property value which I set in kendo initialization (see capture):
@(
Html.Kendo().AutoComplete()
.Name("products")
.Placeholder("Find Product...")
.DataTextField("Name")
.Template("<span><img src='/Content/Images/default-photo.jpg' " +
"width='20' height='20' /> ${data}</span>")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetProducts", "Search")
.Data("onAdditionalData");
})
.ServerFiltering(true);
})
)
<script>
function onAdditionalData() {
return {
text: $("#products").val()
};
}
</script>
After I click this item the name is showing properly:
My action return type is return Json(products, JsonRequestBehavior.AllowGet);
where products is ICollection<VmProduct>
Whats going on?
Upvotes: 1
Views: 1202
Reputation: 21465
You've set the DataTextField
but you're overwriting it when you set the Template
, because kendo will execute the template instead of getting the field you set. But that's not the problem, the problem is that in your template you're printing the data
object, which is.. an object actually. You need to print it's property related to the suggestion text, e.g.:
.Template("<span><img src='/Content/Images/default-photo.jpg' " +
"width='20' height='20' /> ${data.Name}</span>")
Give it a try and tell us what happens.
Upvotes: 1