views:

200

answers:

2

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 ?

+1  A: 

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.

Daniel A. White
does it makes any difference, like for example the page is going be rendered faster, or there is going to be less memory used with ViewResult instead of ActionResult or something like that ?
Omu
No it doesn't really matter at all. The ASP.NET MVC convention is having the return type be `ActionResult` and you return a derived type.
Daniel A. White
A: 

You should use ViewResult to make code more readable and find bugs easier, but there can be other benefits too.

Since I use POST-REDIRECT-GET pattern, I wrote some tests to check if every [HttpPost] method returns RedirectToRouteResult. If I define other type of result in [HttpPost] method, it automatically doesn't pass test. This prevents me from returning View(model) in post method.

LukLed