0

What am i missing? i am trying to do the following:

public JsonResult LoggedOn()
    {


        ViewBag.FirstName = "todd";
        ViewBag.LastName = "billings"
        ViewBag.Email = "me@rad.com";

        return Json(ViewBag, JsonRequestBehavior.AllowGet);

    }

The result in the js making this call is NULL/empty? There is no built in conversion of viewbag to JSON result? What am i missing? If do this with any other object it converts it to JSON.

billy jean
  • 1,399
  • 4
  • 25
  • 45

1 Answers1

0

ViewBag is a ExpandoObject as such there's nothing for the json converter to reflect against. Your best bet here would probably be to make an anonymous object rather than rely on the ViewBag

Here's an example found on stackoverflow: Can I serialize an ExpandoObject in .NET 4?

Community
  • 1
  • 1
Buildstarted
  • 26,529
  • 10
  • 84
  • 95
  • 2
    BuildStarted is correct, you need to do something like this : return Json(new {FirstName = "todd", LastName = "billings", Email = "me@rad.com"}, JsonRequestBehavior.AllowGet); – Paul Jul 16 '11 at 04:50