This is a migrated thread and some comments may be shown as answers.

Format text returned from JSON with line breaks

2 Answers 716 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Carl
Top achievements
Rank 1
Carl asked on 02 Jan 2014, 11:52 PM
Hello Kendo,

I have a ToolTip widget that is receiving data returned from a JSON call. Here is the data call:

public JsonResult GetCountsForSessions(int Id)
        {
           //hard coded data call for testing
            string CountsForSessions = Id.ToString() +  "<br />";
            CountsForSessions += "Item 1 info <br />";
            CountsForSessions += "Item 2 Info <br />";            
            return this.Json(CountsForSessions, JsonRequestBehavior.AllowGet);            
        }

The ToolTip does display the correct data, but the <br> tags are ignored and the resulting text displayed in the ToolTip looks like:

"1077 \u003cbr /\u003eItem 1 info\u003cbr /\u003eItem 2 Info3 \u003cbr /\u003e"

With no like breaks. My goal is to get the data to display in the ToolTip like:

1077
Item 1 info
Item 2 Info

How can  achieve this formatting? Thanks for the help,

Carl


2 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 03 Jan 2014, 02:57 PM
Hi Carl,

I am afraid that displaying JSON data is not supported out of the box. Although this behavior could be achieved using a custom solution, I would recommend you to use partial views, as demonstrated here. Your code might look like this: 
//The Controller:
        public ActionResult GetItemsInfo()
        {
            ViewBag.ID = 123;
            ViewBag.items = new[] {
                "Item 1 info",
                "Item 2 info",
                "Item 3 info",
            };
            return PartialView();
        }
 
//The GetItemsInfo.cshtml partial view: 
    @(ViewBag.id) <br />
    @foreach (var item in ViewBag.items){
            @item <br />
    }
 
//The view:
@(Html.Kendo().Tooltip()
    .For("#...")
    ....
    .LoadContentFrom("GetItemsInfo", "Tooltip")
)


Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Carl
Top achievements
Rank 1
answered on 03 Jan 2014, 04:36 PM
Hi Alexander,

Thanks for the reply and the suggested solution. I implemented your idea and all works well. 

Thanks again,

Carl
Tags
ToolTip
Asked by
Carl
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Carl
Top achievements
Rank 1
Share this question
or