advertisement

Difference between ActionResult() and ViewResult()

63 %
38 %
advertisement
Information about Difference between ActionResult() and ViewResult()
Technology

Published on March 10, 2014

Author: umarali1981

Source: slideshare.net

Description

Difference between ActionResult() and ViewResult()
advertisement

S.No ActionResult() ViewResult() 1 What is ActionResult() ? ActionResult() is a general result type that can have several subtypes. ActionResult() is an abstract class. ActionResult() is a base class for ViewResult() In MVC framework, it uses ActionResult class to reference the object our action method returns. And invokes ExecuteResult method on it. What is ViewResult() ? ViewResult() renders a specifed view to the response stream. ViewResult() is a concrete class. ViewResult() is a derived class of ActionResult() ViewResult is an implementation for this abstract class (ActionResult 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. 2 What are the subtypes of ActionResult class? . 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 What are the subtypes of ViewResult class? As it is a concrete class, so subtypes are not available for ViewResult class.

• FilePathResult - Returns a file to the client 3 Example: (OR) "ActionResult" can be used to exploit polymorphism and dynamism. So if we are returning different types of view dynamically "ActionResult" is the best thing. For example in the above code snippet we can see we have a simple action called as "DynamicView". Depending on the flag ("IsHtmlView") it will either return "ViewResult" or "JsonResult". Example: 4 When to go for ActionResult class ? If our action method may have different behavior, like either render a view or perform a redirection. We can use the more general base class ActionResult as the return type. When to go for ViewResult class ? If we are sure that our action method will return some view page, we can use ViewResult. Reference: http://onlydifferencefaqs.blogspot.in/2014/03/difference-between-actionresult-and.html

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

asp.net - Difference Between ViewResult() and ActionResult ...

What is the difference between ViewResult() and ActionResult() in ASP.NET MVC? public ViewResult Index() { return View(); } public ActionResult Index ...
Read more

What's the difference between ActionResult and ViewResult ...

What's the difference between ActionResult and Vie ... What's the difference between ActionResult and ViewResult for action method? Jul 17, ...
Read more

Difference Between ViewResult() and ActionResult() in MVC ...

So you have hit this blog note because you are confused about the difference between “ViewResult” and “ActionResult” and I hope that ...
Read more

Difference between ActionResult() and ViewResult ...

Blog: Provides a list of Dotnet FAQS which are of Difference between kind. Blog Category: Content Aggregation Total Posts: 255 Total Questions ...
Read more

MVC3 ViewResult vs ActionResult - CodeProject

I want to know the difference between ViewResult and ActionResult What will be the difference of below two action methods? and how can one ...
Read more

ASP.NET MVC interview questions and answers:-What is the ...

In this article we will explain What is the difference between .Net ... What is the difference between "ActionResult" and "ViewResult" in MVC ...
Read more

Difference Between ViewResult() and ActionResult ...

Notify me of new comments via email. Notify me of new posts via email.
Read more

What is the difference Between ViewResult() and ...

What is the difference between ActionResult and ViewResult? What is the structure of ActionResult return type in MVC framework?? What is the difference ...
Read more

MVC - Difference Between Viewresult() and ActionResult ...

What is the difference between using ViewResult() and ActionResult() in ASP.NET MVC framework? For example:
Read more