Introduction

In ASP.NET MVC, every controller action method returns a result to the browser. This result tells the MVC framework what response should be sent to the user.

For example:

  • Show a View page

  • Return JSON data

  • Redirect to another page

  • Return plain text

  • Return a file download

To handle these situations, ASP.NET MVC provides different Action Result return types.

Understanding when to use each return type is very important for building MVC applications.

What is ActionResult?

ActionResult is the base class for many result types in MVC.

Example:

Code
public ActionResult Index()
{
    return View();
}

Here the action method returns a ViewResult, but the return type is written as ActionResult.

Why use ActionResult?

Because it allows the method to return different types of results.

Example:

Code
public ActionResult Test()
{
    if(true)
        return View();
    else
        return RedirectToAction("Index");
}

Types of Return Types in MVC

Below are the most commonly used return types.

Return TypePurpose
ViewResultReturns a View page
PartialViewResultReturns Partial View
ContentResultReturns plain text
JsonResultReturns JSON data
RedirectResultRedirects to another URL
RedirectToRouteResultRedirects to another action
FileResultReturns a file
EmptyResultReturns nothing

1 ViewResult

ViewResult is used to display a View page.

Example Controller:

Code
public ViewResult Index()
{
    return View();
}

This will open:

Code
Views/Home/Index.cshtml

Passing Data to View

Code
public ActionResult Index()
{
    ViewBag.Message = "Welcome to MVC";
    return View();
}

View:

Code
<h2>@ViewBag.Message</h2>

What is this?

Output:

Code
Welcome to MVC

2 PartialViewResult

Used to return partial views.

Partial views are small reusable UI components.

Example:

Controller

Code
public PartialViewResult StudentList()
{
    return PartialView();
}

Partial View file:

Code
_StudentList.cshtml

When to Use

  • AJAX requests

  • Reusable UI sections

  • Updating part of a page

3 ContentResult

Used to return simple text content.

Example:

Code
public ContentResult Message()
{
    return Content("Hello MVC Developers");
}

Output in browser:

Code
Hello MVC Developers

When to Use

  • Simple text response

  • Testing APIs

  • Debugging

4 JsonResult

Used to return JSON data.

Mostly used in AJAX calls.

Example:

Code
public JsonResult GetStudent()
{
    var student = new
    {
        Id = 1,
        Name = "Abhay",
        City = "Ahmedabad"
    };

    return Json(student, JsonRequestBehavior.AllowGet);
}

Output

Code
{
 "Id":1,
 "Name":"Abhay",
 "City":"Ahmedabad"
}

When to Use

  • AJAX requests

  • API responses

  • JavaScript data handling

5 RedirectResult

Used to redirect to another URL.

Example:

Code
public RedirectResult GoToGoogle()
{
    return Redirect("https://www.google.com");
}

Browser will open Google.

6 RedirectToRouteResult

Used to redirect to another controller action.

Example:

Code
public ActionResult RedirectExample()
{
    return RedirectToAction("Index", "Home");
}

This will redirect to:

Code
HomeController → Index Action

7 FileResult

Used to return files to download.

Example:

Code
public FileResult DownloadFile()
{
    return File("~/Files/sample.pdf", "application/pdf");
}

The browser will download the file.

When to Use

  • PDF download

  • Excel download

  • Image download

8 EmptyResult

Used when no response is required.

Example:

Code
public EmptyResult Test()
{
    return new EmptyResult();
}

This returns nothing to the browser.

Returning Different Data Types to View

In MVC we can send many types of data to views.

1 Using ViewBag

Controller

Code
public ActionResult Index()
{
    ViewBag.Name = "Abhay";
    ViewBag.Age = 22;
    return View();
}

View

Code
<h2>@ViewBag.Name</h2>
<h2>@ViewBag.Age</h2>

What is this?

2 Using ViewData

Controller

Code
public ActionResult Index()
{
    ViewData["City"] = "Ahmedabad";
    return View();
}

View

Code
<h2>@ViewData["City"]</h2>

What is this?

3 Passing Model Data

Model

Code
public class Student
{
    public int Id {get;set;}
    public string Name {get;set;}
}

Controller

Code
public ActionResult Details()
{
    Student s = new Student();
    s.Id = 1;
    s.Name = "Abhay";

    return View(s);
}

View

Code
@model Student

<h2>@Model.Id</h2>
<h2>@Model.Name</h2>

When to Use Which Return Type

SituationReturn Type
Display pageViewResult
Load part of pagePartialViewResult
Return plain textContentResult
Return JSON for AJAXJsonResult
Redirect to another actionRedirectToRouteResult
Redirect to URLRedirectResult
Download fileFileResult
No output neededEmptyResult

Real Example (Multiple Return Types)

Code
public ActionResult Example()
{
    if(DateTime.Now.Hour < 12)
    {
        return View();
    }
    else
    {
        return RedirectToAction("Index");
    }
}

Here one action method can return two different results.

Important Tip for Beginners

Most developers simply use:

Code
public ActionResult Index()

Instead of writing:

Code
public ViewResult Index()

Why?

Because ActionResult allows multiple result types in the same method.

Conclusion

Return types are a fundamental concept in ASP.NET MVC controllers. They define what kind of response should be sent back to the browser.

Using the correct return type improves:

  • Application structure

  • Performance

  • Maintainability

The most commonly used return types are ViewResult, JsonResult, RedirectResult, and FileResult.

Once beginners understand these return types, building MVC applications becomes much easier.