Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this kendo dropdownlist to populate with json result.

The code for kendo dropdownlist is :


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



The method to return json data is:


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



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`"}]
Posted
Updated 8-Apr-16 5:44am

1 solution

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900