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 ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With