What is the difference between JsonResult and ActionResult?

What is the difference between JsonResult and ActionResult?

Use JsonResult when you want to return raw JSON data to be consumed by a client (javascript on a web page or a mobile client). Use ActionResult if you want to return a view, redirect etc to be handled by a browser. ActionResult is an abstract class . JsonResult is subtype of ActionResult .

What is controller ActionResult?

An ActionResult is a return type of a controller method, also called an action method, and serves as the base class for *Result classes. Action methods return models to views, file streams, redirect to other controllers, or whatever is necessary for the task at hand.

What are the sub types of ActionResult?

ActionResult Subtypes In MVC

  • ViewResult – Renders a specified view to the response stream.
  • PartialViewResult – Renders a specified partial view to the response stream.
  • EmptyResult – An empty response is returned.
  • RedirectResult – Performs an HTTP redirection to a specified URL.

What do you mean by ViewResult ()?

ViewResult – Renders a specified view to the response stream. PartialViewResult – Renders a specified partial view to the response stream. EmptyResult – An empty response is returned. RedirectResult – Performs an HTTP redirection to a specified URL.

What’s the difference between actionresult and viewresult ( )?

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.

Why is contentresult data type in the action method?

The first part of the question is: “Why there is ContentResult data type in the action method?”. To understand this, you have to understand the data types in ASP.NET MVC 5 because the ContentResult is a data type whose base data type is ActionResult, hence you have to understand Action Result.

What is the action result in ASP.NET MVC?

Action Result in ASP.NET MVC. Action Result is actually a data type. When it is used with action method, it is called return type. As you know, an action is referred to as a method of the controller, the Action Result is the result of action when it executes. In fact, Action Result is a return type. This return type has many other derived types.

Which is the viewresult method in ASP.NET Core?

Possibly the most basic Result class in all of ASP .NET Core MVC is the ViewResult class (short method: View () ), which returns a view. Note that, by default, the View () method returns a view with the same name as the action it is called from, in a folder with the same name as the controller.

About the Author

You may also like these