Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7779049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:33:08+00:00 2026-06-01T18:33:08+00:00

timeline.js + MVC + Ajax + JSON hello, I have problem while converting string

  • 0

timeline.js + MVC + Ajax + JSON

hello,

I have problem while converting string to Json Object

I have to display timeline on my webpage, I have used Timeline.js for the same, I am able to run the timeline using static data that is as following

Static Data

// Create a JSON data table
data = [
{
        'start': new Date(2010, 7, 23),
    'content': 'Conversation'
},
{
    'start': new Date(2010, 7, 23),
    'content': 'New Conversation'
},
{
    'start': new Date(2010, 7, 23),
    'content': 'Very New Conversation'
}

now when I do

alert(data);

it gives me

[object Object],[object Object],[object Object]

but now I have to display a data from the DB, so I am calling the following function on controller

GetTimeLine method on controller

public JsonResult GetTimeline()
{
      JsonResult jr = new JsonResult();
      var objtimeline = objEntities.Timelines.Where(tl => tl.StudentID == Sessions.StudentID).ToList().AsQueryable();
      String newstr = "[";
      foreach(var tml in objtimeline)
      {
            DateTime date1 = Convert.ToDateTime(tml.CalculatedDate);
            newstr += "{'start': new  Date("+date1.Year+","+date1.Month+","+date1.Day+","+date1.Hour+","+date1.Minute+","+date1.Second+"),'content':'"+tml.Description+"'},";
      }
      newstr = newstr.TrimEnd(',');
      newstr += "];";
      jr.Data = newstr;
      jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
      return jr;
}

function to call controller method

jQuery.ajax({
    type: "POST",
    url: "@Url.Content("~/Student/GetTimeline")",
    success: function (result) {
        data = result;
    },
});
alert(data);

it gives me the following alert

[{'start': new Date(2012,2,11,0,0,0),'content':'Parents meeting'},{'start': new Date(2012,2,15,0,0,0),'content':'Exam Meeting'}];

so the problem is with conversion of string to Json Object,

How can I convert string returned from controller to Json Object on my view…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:33:10+00:00Added an answer on June 1, 2026 at 6:33 pm

    You’re working too hard. Let the framework do it for you.

    public JsonResult GetTimeline()
    {
         var timeline = objEntities.TimeLines.Where( tl => tl.StudentID == Sessions.StudentID )
                                             .ToList() //required due to Convert call
                                             .Select( tl => new
                                              {
                                                   start = Convert.ToDateTime(tl.CalculatedDate),
                                                   content = tl.Description
                                              });
         return Json( timeline, JsonRequestBehavior.AllowGet );
    }
    

    Then either use getJSON (since you specifically allow gets) or specify dataType: 'json' in your request.

    $.getJSON( '@Url.Action("gettimeline","student")', function(data) {
         alert(data);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am parsing the public timeline xml from twitter and want to display images
I'm converting over a web-app to use the MVC structure of Zend Framework. I
I've this json return { timeline: [{ id: 2, self: { uid: 2, username:
I'm working on 'timeline' project, where I have content inside of list items, in
I am looking for a simple timeline chart, that I can display several events
In history-books you often have timeline, where events and periods are marked on a
I have a MovieClip on the main timeline on frame 5. It's called slideShow_mc.
I have a timeline with little pins on it which when hovered over, slide
I have the following code on the timeline, but when I try and output
I have an UITableView populated with a Twitter timeline. I also have scroll to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.