Click here to Skip to main content
15,903,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to know the difference between ViewResult and ActionResult

What will be the difference of below two action methods? and how can one decide when to use ViewResult or ActionResult
C#
public ActionResult Index()
       {

           return View();
       }

public ViewResult Index()
       {

           return View();
       }
Posted
Updated 4-Oct-12 3:27am
v2

ActionResult -is an abstract class that can have several subtypes:

ViewResult - Renders a specifed view to the response stream
 
Share this answer
 
Comments
fjdiewornncalwe 4-Oct-12 9:28am    
Please don't answer questions that are this old and already have answers. The likelihood that the OP is still looking for an answer to this question over 1 year later is pretty slim.
Don Nichol 20-Dec-13 18:17pm    
Other people come here looking for answers, not just the OP. Answers are always appreciated.
ActionResult is an abstract class that can have several subtypes.

ActionResult Subtypes

ViewResult - Renders a specifed view to the response stream

PartialViewResult - Renders a specifed partial view to the response stream

EmptyResult - An empty response is returned

RedirectResult - Performs an HTTP redirection to a specifed URL

RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data

JsonResult - Serializes a given ViewData object to JSON format

JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client

ContentResult - Writes content to the response stream without requiring a view

FileContentResult - Returns a file to the client

FileStreamResult - Returns a file to the client, which is provided by a Stream

FilePathResult - Returns a file to the client
 
Share this answer
 
Comments
CHill60 27-Feb-14 8:38am    
To quote Marcus Kramer "Please don't answer questions that are this old and already have answers. The likelihood that the OP is still looking for an answer to this question over 2 years later is pretty slim.". The comment from Don Nichol does not apply as you have copied this from this 2 year old post[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900