Various Types of Action Results and usage in Mvc

There are Different Types of action result in Mvc .Different Action result have different purpose.Let us understand the action result below.

Action result is the Base Class for all result class
ActionResult Types Description
ViewResult:
  • return a view to render HTML in the browser.
  • Most Common and Default Result
PartialViewResult: return a Partial view
ContentResult: return any type of content.By default, it is used to return plain text, but the actual content type can be explicitly defined (e.g. text/xml).
EmptyResult: equivalent of a void method
FileResult: Used to return binary content (e.g., if you want to download a file).
HttpUnauthorizedResult:
  • You can return an HttpUnauthorizedResult object when the request tries to access restricted content
  • Eg)When Anonymous users request to see a webapage ,it redirects to login page
JavaScriptResult: Return a Js code
JsonResult: return object in jSon Format
RedirectResult: Used to perform an HTTP redirect to another URL.
RedirectToRouteResult:used to perform an HTTP redirect, but to a specific route rather than a URL.

Comments