ActionResult or JsonResult returning Json?

3

I see a lot of code in Controller where it is used as method ActionResult returning Json() , but I also see an approach using method JsonResult logically returning Json .

Are there any differences between these two approaches? Is there a correct standard to use?

    
asked by anonymous 19.04.2018 / 17:12

1 answer

5

In class JsonResult we have an inheritance of ActionResult :

public class JsonResult : ActionResult

If you choose to return a JsonResult you will have to return ONLY JsonResult , choosing the ActionResult approach you have more flexibility to return a Action OU JSON since a Action is a ActionResult and JSON also because it inherits ActionResult .

In my opinion it's good to use ActionResult when you have the chance to return Action OR JSON . If you are sure that the return must always be JSON use JsonResult .

    
19.04.2018 / 17:46