Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonResult or Json: which to use?

In ASP.NET MVC 3, which is more correct to use: Json() or new JsonResult()? Either returns the same result. Thanks for helping solve an office debate.

like image 734
Darth Coder Avatar asked Jul 20 '11 18:07

Darth Coder


1 Answers

Json() is just an extension method that actually returns a JsonResult object behind the scenes (rather than needing to call the constructor directly).

I almost always use the Extension Method myself. This keeps more in line with the other common return types from Action Methods like View(), PartialView(), etc.

I also make sure to create an extension method for any custom ActionResult types that I create. In the end it's a matter of personal preference.

like image 175
Justin Niessner Avatar answered Oct 19 '22 18:10

Justin Niessner