Reputation: 2465
I am using Kendo UI Dropdownlist with ASP.NET MVC5. I want to write a cookie onSelect:
@(Html.Kendo().DropDownList().Name("sss").BindTo(Model).DataTextField("Name").DataValueField("Id")
.Events(e =>
{
e.Select("onSelect");
})
.Deferred()
)
function onSelect(e) {
if ("sss" in window) {
debugger;
var dataItem = this.dataItem(e.item);
alert(dataItem.value);
setCookie(dataItem.value);
}
}
all the functions are reachable and working fine. but I am getting an:
undefined
value instead of Id. why am I receiving this error? and how can I fix it?
P.S. the Model contain both Id and Name.
Upvotes: 0
Views: 199
Reputation: 3169
Once you get the dataItem, it is an instance of your model used to populate the DropDownList.
So, in order to access the Id field, use the Id field not the value field(which your model does not have).
function onSelect(e) {
if ("sss" in window) {
debugger;
var dataItem = this.dataItem(e.item);
alert(dataItem.Id);
setCookie(dataItem.Id);
}
}
Upvotes: 2