Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 ASP.NET MVC 3 中,使用哪个更正确:Json()或new JsonResult()?要么返回相同的结果。感谢您帮助解决办公室辩论。
Json()
new JsonResult()
Json()只是一个扩展方法,实际上在JsonResult后台返回一个对象(而不是需要直接调用构造函数)。
JsonResult
我自己几乎总是使用扩展方法。这与来自 Action 方法(如View(),PartialView()等)的其他常见返回类型更加一致。
View()
PartialView()
我还确保为我创建的任何自定义 ActionResult 类型创建扩展方法。最后,这是个人喜好的问题。