Difference between ViewResult and ActionResult

5

What is the difference between ViewResult and ActionResult? Normally I call a View using an ActionResult, but I've already seen code with ViewResult. Then came this doubt.

    
asked by anonymous 21.04.2016 / 23:15

2 answers

6

ViewResult drift ActionResult . ActionResult is abstract, and serves as a wildcard in return, which can be:

21.04.2016 / 23:29
4

From an answer from the ASP.NET forum : ActionResult is an abstract class, and has variás derived classes, including ViewResult . If you are going to return your ViewResult method in your method, you can declare it by returning ActionResult as ViewResult.

Here are some classes derived from ActionResult:

  • ViewResult
    • Returns a view to be rendered in response
  • PartialViewResult
    • Returns a partial view to be rendered in response
  • EmptyResult
    • "Nothing"; an empty response (HTTP response with content of size 0, or 204 No Content)
  • RedirectResult
    • Returns a redirect (HTTP 3xx) to the specified URL
  • RedirectToRouteResult
    • Returns a redirect (HTTP 3xx) for the specified route
  • JsonResult
    • Returns a data in the format JSON (application / json)
21.04.2016 / 23:26