如何使用json结果加载kendo下拉列表 [英] How to load kendo dropdownlist with json result

查看:91
本文介绍了如何使用json结果加载kendo下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个kendo下拉列表来填充json结果。



kendo下拉列表的代码是:





I have this kendo dropdownlist to populate with json result.

The code for kendo dropdownlist is :


@(Html.Kendo().DropDownList()
                             .Name("DropDownListMessageTemplates")
                             .DataTextField("TemplateValue")
                             .DataValueField("TemplateId")
                             .DataSource(datasource => datasource
                                                   .Read(read => read.Action("GetMessageTemplateJson", "Employee"))
                                                   .ServerFiltering(true)
                                               )
                             .SelectedIndex(0)
                       )







返回json数据的方法是:








The method to return json data is:


public JsonResult GetMessageTemplateJson()
       {
           var messageList = _context.MessageTemplate.ToList();
           var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(messageList);
           return this.Json(json, JsonRequestBehavior.AllowGet);
       }







这里的json结果返回值为:



[{TemplateId:1,TemplateValue:嗨@Employee,你想上任并谈谈最近的工作机会。谢谢},{TemplateId :2,TemplateValue:嗨@Employee,请到办公室听取更多关于适合你的工作。谢谢},{TemplateId:3,TemplateValue:你好@Employee,问候。我会的想跟你谈谈@location的新机会。请回复。谢谢你``}}





但我是在下拉列表中看到未定义,如果我转到其中的每个值,我可以看到[,{等类型的值。





有人可以帮忙用这个来看看每个值而不是单个字符。



谢谢



我尝试过:



[{TemplateId:1,TemplateValue:嗨@Employee,你想要吗?来吧冰和谈论最近的工作机会。谢谢},{TemplateId:2,TemplateValue:嗨@Employee,请到办公室听取更多关于适合你的工作。谢谢},{TemplateId:3,TemplateValue:Hello @Employee,Greetings。我想和你谈谈@location的新机会。请回复。谢谢你``}}




Here the json result is returning values as :

[{"TemplateId":1,"TemplateValue":"Hi @Employee, would you like to come to office and talk about the recent job opportunity. Thanks"},{"TemplateId":2,"TemplateValue":"Hi @Employee, please come to office for hearing more about job suitable to you. Thanks"},{"TemplateId":3,"TemplateValue":"Hello @Employee, Greetings. I would like to talk to you about new opportunity here in @location. Please reply back. Thank you`"}]


But I am seeing undefined in the dropdownlist and if I go to each values in that, I can see [, {, etc type of values.


Can someone please help with this one to see each value instead of single characters.

Thank you

What I have tried:

[{"TemplateId":1,"TemplateValue":"Hi @Employee, would you like to come to office and talk about the recent job opportunity. Thanks"},{"TemplateId":2,"TemplateValue":"Hi @Employee, please come to office for hearing more about job suitable to you. Thanks"},{"TemplateId":3,"TemplateValue":"Hello @Employee, Greetings. I would like to talk to you about new opportunity here in @location. Please reply back. Thank you`"}]

推荐答案

它比你编写的代码容易得多:

It's far easier than the code you've written:
public JsonResult GetMessageTemplateJson()
{
    var messageList = _context.MessageTemplate.ToList();
    return Json(messageList, JsonRequestBehavior.AllowGet);
}


这篇关于如何使用json结果加载kendo下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆