What are the different return types of action method in controller?

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

ViewResult: It returns a view that renders HTML to be sent to the client.

PartialViewResult: It returns a partial view that is rendered within another view.

JsonResult: It returns JSON data that can be consumed by client-side JavaScript code.

ContentResult: It returns a string of content that is directly written to the response stream. This is useful for returning plain text, XML, or other non-HTML content.

FileResult: It returns a file to the client for download, such as a PDF, image, or video.

RedirectToRouteResult: It redirects the client to another action method based on a specified route.

RedirectResult: It redirects the client to a specified URL.

HttpNotFoundResult: It returns a 404 Not Found status code to the client.

HttpStatusCodeResult: It returns an HTTP status code to the client, such as 401 Unauthorized or 500 Internal Server Error.

EmptyResult: It returns an empty response to the client without any content.


 

Post a Comment

Previous Post Next Post