I have objects to bind to an AutoComplete. They have Id and Name properties. I want to auto-complete on the Name and get access to the corresponding Id when an item is selected. For test purposes I'm including the Id in the string that gets bound as the Name. For test purposes I'm issuing an alert() with the details of the dataItem selected.
@(Html.Kendo().AutoCompleteFor(model => model.SelectedItem)
.BindTo(Model.AvailableItems.Select(x => new { x.Id, Name = string.Format("{0} ({1})", x.Name, x.Id) }))
.DataTextField("Name")
.Events(e => e.Select("onSelect"))
.Filter("contains")
)
<script>
function onSelect(e) {
var dataItem = this.dataItem(e.item.index());
alert(dataItem.Id + ":" + dataItem.Name + "(" + e.item.index() + ")");
}
</script>
What I'm seeing is that in most cases (not all cases, which is even more curious to me), the Id and Name of the apparently selected dataItem don't correspond. The Id seems to (usually) be that of the NEXT item in the list after the one with the selected Name.
Any ideas? I can try to reproduce it in a standalone sample when I get the chance..
@(Html.Kendo().AutoCompleteFor(model => model.SelectedItem)
.BindTo(Model.AvailableItems.Select(x => new { x.Id, Name = string.Format("{0} ({1})", x.Name, x.Id) }))
.DataTextField("Name")
.Events(e => e.Select("onSelect"))
.Filter("contains")
)
<script>
function onSelect(e) {
var dataItem = this.dataItem(e.item.index());
alert(dataItem.Id + ":" + dataItem.Name + "(" + e.item.index() + ")");
}
</script>
What I'm seeing is that in most cases (not all cases, which is even more curious to me), the Id and Name of the apparently selected dataItem don't correspond. The Id seems to (usually) be that of the NEXT item in the list after the one with the selected Name.
Any ideas? I can try to reproduce it in a standalone sample when I get the chance..