top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference Between ViewResult() and ActionResult()?

+4 votes
597 views
What is the difference Between ViewResult() and ActionResult()?
posted May 26, 2014 by Merry

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
 
Best answer

ActionResult is an abstract class and it is base class for ViewResult class.

In MVC framework, it uses ActionResult class to reference the object your action method returns. And invokes ExecuteResult method on it.

And ViewResult is an implementation for this abstract class. It will try to find a view page (usually aspx page) in some predefined paths(/views/controllername/, /views/shared/, etc) by the given view name.

It's usually a good practice to have your method return a more specific class. If you are sure that your action method will return some view page, you can use ViewResult. But if your action method may have different behavior, like either render a view or perform a redirection. You should use the more general base class ActionResult as the return type.

Source: http://forums.asp.net/t/1448398.aspx?What+s+the+difference+between+ActionResult+and+ViewResult+for+action+method+

answer May 27, 2014 by Santosh Prasad
...