1

If I have an action method that I know it will only be called via AJAX and always returning JSON...

Do I set the method return type to JsonResult or leave it to ActionResult?

Please explain the reason of the choice.

empz
  • 11,509
  • 16
  • 65
  • 106

1 Answers1

0

You should declare your action methods as returning ActionResult, so that they have the freedom to return any concrete result class.

Check this answer: https://stackoverflow.com/a/15250991/7720

Community
  • 1
  • 1
Romias
  • 13,783
  • 7
  • 56
  • 85
  • Yes but, do I want that freedom if I know for sure I'm expecting a JsonResult? – empz Mar 22 '14 at 02:31
  • If you are sure that the return result is JSON you dont have to specify `ActionResult`. Although jsonresult inherits actionresult so it doesnt matter! Note you can return simple string as well from an Action – Nilesh Mar 22 '14 at 05:35