Complete C# Tutorial

Mastering ViewResult, JsonResult, RedirectResult in .NET Core — Super Simple Guide!

👋 Introduction

Welcome back, my friend! 😊
Today, you will learn three powerful action method return types in ASP.NET Core MVC: ViewResult, JsonResult, RedirectResult.

These three heroes decide what your controller sends back — a webpage, JSON, or a redirect.
And trust me… once you understand them, your MVC projects will suddenly feel easy, clean, and fun ✨

🧠 Understanding the Basics

1️⃣ ViewResult

Used when you want to return an HTML view.
Like showing a webpage to the user.

2️⃣ JsonResult

Used when you want to return JSON data.
Perfect for APIs and AJAX calls.

3️⃣ RedirectResult

Used when you want to send the user to another URL or action.
Great when you want to move them after saving data.

Together, these three — ViewResult, JsonResult, RedirectResult — form the “Return-Type Trio” of MVC 😄

💻 Code Example

Here’s a simple controller demonstrating ViewResult, JsonResult, RedirectResult in one place:

				
					using Microsoft.AspNetCore.Mvc;

public class DemoController : Controller
{
    // 1. ViewResult example
    public IActionResult ShowPage()
    {
        return View();  // returns a ViewResult
    }

    // 2. JsonResult example
    public IActionResult GetProduct()
    {
        var product = new { Id = 1, Name = "Laptop", Price = 55000 };
        return Json(product);  // returns a JsonResult
    }

    // 3. RedirectResult example
    public IActionResult GoToGoogle()
    {
        return Redirect("https://www.google.com");  // returns RedirectResult
    }
}
				
			

📤 Expected Output

🟦 Output of ShowPage()

A normal webpage (your MVC view).

🟧 Output of GetProduct()

				
					{
  "id": 1,
  "name": "Laptop",
  "price": 55000
}
				
			

🟥 Output of GoToGoogle()

Browser jumps to google.com instantly.

🏠 Real-Life Scenario (Very Practical)

Imagine you’re building an online shop.

  1. When the user opens the product page, you return a ViewResult.
  2. When the same user clicks “Refresh Stock”, your app calls AJAX and you return JsonResult with updated stock.
  3. After the user buys something, you redirect them to a Thank You page using RedirectResult.

See?
Our trio — ViewResult, JsonResult, RedirectResult — works together just like teammates in a cricket match 🏏 each with a different role.


👌 Final Thoughts

You just learned one of the most important concepts in ASP.NET Core controllers.
Next time someone asks you what ViewResult, JsonResult, RedirectResult do, you can explain in 10 seconds!


👉 Next what?

In the next chapter you will learn “ViewResult, JsonResult, RedirectResult”

Can’t wait to continue this journey with you 🚀 Let’s keep going!

Leave a Comment

sixteen − 4 =

Share this Doc

Returning Results (ViewResult, JsonResult, RedirectResult)

Or copy link