Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewResult or ActionResult | does it makes sense to use ViewResult if ActionResult is good for everything anyways?

In asp.net mvc there is ViewResult for returning a View and ActionResult for returning whatever you want, so is there some good reason why should I use ViewResult instead of ActionResult when I'm sure that I will return a View ?

like image 336
Omu Avatar asked Mar 20 '10 20:03

Omu


2 Answers

ActionResult is the general base class that all the other results are derived from like ViewResult,JsonResult and so on.

This way you can return multiple types of results like JSON and XML from the same method.

like image 134
Daniel A. White Avatar answered Sep 19 '22 18:09

Daniel A. White


It's for the same reason you don't write every method of every class to return "object". You should be as specific as you can. This is especially valuable if you're planning to write unit tests. No more testing return types and/or casting the result.

like image 24
RickAndMSFT Avatar answered Sep 20 '22 18:09

RickAndMSFT