2

I'm working on MVC project and i using jQuery in view page to get data from controller.

public JsonResult CheckUpdate()
{
  dt = dt.AddSeconds(-100);

  IQueryable<Tweet> _tweet = ttr.CheckTime(dt);

  return Json(_tweet, JsonRequestBehavior.AllowGet);
}

This is a method in my controller which gets data back from the repository class and returns it as JSON to my view page, which uses jQuery to get it.

When i run program and inspect in Firebug, it shows me an error which is:

A circular reference was detected while serializing an object of type 'TweetTrafficReport.Models.User'

My question is

  • Is it correct that i return JSON data which it is IQueryable type
  • How can i use JSON data in my view page and not get an error like above

Thanks for ur help :)

2 Answers 2

2

The circular reference i bet is because of the fact you have your Tweet object reference inReplyTo

IQueryable Really isnt as big an issue as casting each Tweet as a JsonCapableTweet like hanselman does http://nerddinnerbook.s3.amazonaws.com/Part11.htm

however it does help to lolok at the way Twitter does this

http://search.twitter.com/search.json?callback=foo&q=twitter

thats pretty nice json they return, matching yours to theirs is a good habit to have

Sign up to request clarification or add additional context in comments.

2 Comments

Do you think that the circular reference problem come form what conflict in my database because i try and change belong NerdDinner ur given and it still be the circular reference problem
There is my false in my DB Thank you for ur help
2

You shouldn't really return IQueryable as Json, try returning a ViewModel instead

public JsonResult CheckUpdate()
{

   dt= dt.AddSeconds(-100);

   IQueryable<Tweet> _tweet = ttr.CheckTime(dt);

   var tweetVm = _tweet.Select(t => new TweetViewMode(){ Message = t.Message });

   return Json(tweetVm, JsonRequestBehavior.AllowGet);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.