ASP.NET MVC: Best C# method of building a Json ActionResult

Viewed 9543

Similar questions have been asked in the past, but they seem a little dated now. I'm trying to get the current general consensus on what's the best way to construct a JsonResult in ASP.NET MVC. The context of this question is to use the most current methods available from .NET 4/4.5 & MVC 4

Here's a few popular methods I've come across over the years:

var json1 = new { foo = 123, bar = "abc" };

var json2 = new Dictionary<string, object>{ { "foo", 123 }, { "bar", "abc" } };

dynamic json3;
json3.foo = 123;
json3.bar = "abc";

Please also the explain the pros/cons of your preferred method

1 Answers
Related