1

I recently started working with MVC or MVC2 to be more exact. I found a tutorial yesterday that was using JSON to populate a dropdowlist. Im not sure why this did not work with a MVC2 project and only with a MVC. Anybody got the time to just peep this site and maybe see what it might be? http://www.dotnetcurry.com/ShowArticle.aspx?ID=466. It's that JSON example, its homecontroler and the view code only

I really want to know why

thanks

1
  • What happens when you try it under MVC2? What errors/messages do you get? Commented Mar 30, 2010 at 12:24

1 Answer 1

6

There has been a change to JsonResult in MVC 2 and therefore it will no longer work with HTTP GET to avoid JSON hijacking.

So you could either change your code to return via HTTP POST or allow GET behaviour which may leave you open to JSON hijacking.

Try modifying your code to follow the to the format if you wish to use GET

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetListViaJson()
{
  return Json(GenerateNumbers(), JsonRequestBehavior.AllowGet);
}

Or use the recommended POST

[AcceptVerbs(HttpVerbs.Post)]
public JsonResult GetListViaJson()
{
  return Json(GenerateNumbers());
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the info. The JsonRequestBehavior.AllowGet works for me

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.