Sveta Antrapovich Sveta Antrapovich - 3 months ago 28
ASP.NET (C#) Question

Kendo autocomplete asp.net undefined value

I'm trying to make an autocomplete (asp.net core)

Razor view:

@(Html.Kendo().AutoComplete()
.Name("users")
.Filter("startswith")
.Placeholder("Type user name...")
.DataTextField("Email")
.Events(e =>
{
e.Select("onSelect");
})
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetUsers", "User").Data("onAdditionalData");
})
.ServerFiltering(true);
})
.HtmlAttributes(new { style = "width:30%" })
.MinLength(2)
.Suggest(true)
.Height(400)
.Template("<span class=\"k-state-default\">\\#=users.Email\\#</span>"))


Server side:

[HttpGet]
public dynamic GetUsers(string term)
{
return ctx.Users.Where(x => x.Email.ToUpper().Contains(term.ToUpper()))
.Select(res => new { id = res.Id.ToString(), name = res.Email }).ToList();
}


In my view I always get right number of value, but it is always "undefined". Where I`m wrong?

Answer

You are renaming "Email" to "name" in your server-side action; So you should use

.DataTextField("name")
Comments