开发者

Returning ViewBag as JSONResult result in null data?? wtf?

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开发者_如何学Go 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜