Introduction
In ASP.NET MVC, controller action methods return different types of results depending on what the application needs to send back to the browser.
For example, an action method may return:
A View page
JSON data
A file download
Redirect to another page
These responses are called Action Results.
Understanding return types helps developers choose the correct response type when building web applications.
In this article, we will learn:
What return types are in ASP.NET MVC
Why they are used
Different return types with examples
When to use each return type
What is ActionResult?
ActionResult is the base class for all result types in ASP.NET MVC.
It allows a controller action method to return different types of responses.
Example:
public ActionResult Index()
{
return View();
}
Here the controller returns a ViewResult, but the return type is ActionResult.
This gives flexibility to return different results.
1️⃣ ViewResult
What is ViewResult?
ViewResult returns an HTML view page to the browser.
Example
Controller:
public ViewResult Index()
{
return View();
}
View:
<h2>Welcome to ASP.NET MVC</h2>
What is this?
Output
Welcome to ASP.NET MVC
When to Use
Use ViewResult when you want to display a web page to the user.
2️⃣ PartialViewResult
What is PartialViewResult?
PartialViewResult returns a partial view instead of a full page.
Partial views are reusable UI components.
Example
public PartialViewResult Header()
{
return PartialView("_Header");
}
When to Use
Use when loading small UI sections like:
Header
Footer
Sidebar
AJAX partial content
3️⃣ JsonResult
What is JsonResult?
JsonResult returns JSON data instead of HTML.
This is commonly used in AJAX calls.
Example
public JsonResult GetStudent()
{
var student = new
{
Id = 1,
Name = "Rahul",
Age = 20
};
return Json(student, JsonRequestBehavior.AllowGet);
}
Output
{
"Id":1,
"Name":"Rahul",
"Age":20
}
When to Use
Use JsonResult when sending data to:
4️⃣ ContentResult
What is ContentResult?
ContentResult returns plain text or HTML content.
Example
public ContentResult Message()
{
return Content("Hello from ASP.NET MVC");
}
Output
Hello from ASP.NET MVC
When to Use
Use when returning simple text content.
5️⃣ FileResult
What is FileResult?
FileResult returns a file download to the browser.
Example
public FileResult Download()
{
string path = Server.MapPath("~/Files/sample.pdf");
return File(path, "application/pdf", "sample.pdf");
}
Output
The browser downloads sample.pdf.
When to Use
Use when allowing users to download:
PDF files
Excel files
Images
Documents
6️⃣ RedirectResult
What is RedirectResult?
RedirectResult redirects the browser to another URL.
Example
public RedirectResult GoToGoogle()
{
return Redirect("https://www.google.com");
}
When to Use
Use when redirecting to an external website.
7️⃣ RedirectToRouteResult
What is RedirectToRouteResult?
RedirectToRouteResult redirects to another controller action.
Example
public ActionResult Test()
{
return RedirectToAction("Index");
}
When to Use
Use when navigating between MVC actions.
Example:
After saving data → redirect to List page.
8️⃣ EmptyResult
What is EmptyResult?
EmptyResult returns nothing to the browser.
Example
public EmptyResult DoNothing()
{
return new EmptyResult();
}
When to Use
Use when no response is needed.
Return Types Summary
| Return Type | Purpose |
|---|
| ActionResult | Base return type |
| ViewResult | Return view page |
| PartialViewResult | Return partial view |
| JsonResult | Return JSON data |
| ContentResult | Return text content |
| FileResult | Download files |
| RedirectResult | Redirect to external URL |
| RedirectToRouteResult | Redirect to another action |
| EmptyResult | Return nothing |
Real-World Example
Imagine a student management system.
Different return types may be used:
ViewResult → Show student list page
JsonResult → Send student data using AJAX
FileResult → Download student report
RedirectToAction → Redirect after saving student
Each return type serves a different purpose.
Best Practice
Most developers use ActionResult as the return type.
Example:
public ActionResult Index()
{
return View();
}
This provides flexibility to return different result types later.
Conclusion
Return types in ASP.NET MVC control how data is sent from the controller to the browser.
In this article we learned:
What ActionResult is
Different return types in MVC
When to use each return type
Simple examples for beginners