ASP.NET MVC

Different Types Of Action Results In ASP.NET MVC

Here in this article, we will learn about the different type of action results available in ASP.NET MVC 5. There are various action methods in MVC 5 but ActionResult is the base class for all the action methods available in MVC 5.

There are some restrictions also:

  • It cannot be overloaded
  • It cannot be a static method
  • It must be public, nor private or protected are allowed.

As we can see it is the base class which is defined as abstract class.

Types of Action Results
  • View Result
  • Redirect Result
  • Redirect To Route Result
  • File Result
  • Partial View Result
  • Redirect To Action Result
  • Json Result
  • Content Result

View Result

It returns the view page which has .cshtml extension in controller folder.

public ViewResult ViewDemo()  
       {   
            return View();  
       }

Partial View Result

It returns the partial view as a result. Partial view is placed inside a Normal view page.

public PartialViewResult Sidebar()  
{  
       return PartialView("_Sidebar");  
}

Redirect Result

It returns the result to a specific URL. It renders to the page by URL

public RedirectResult About()  
{  
       return Redirect("Contact");  
}

Redirect to Action Result

It returns the result to the specific controller and action method.

public ActionResult Index()  
{  
        return RedirectToAction("About", "Manage");  
}

Json Result

It is useful when we call the method using the ajax.

public JsonResult Index()  
{   
       return Json("Successful", JsonRequestBehavior.AllowGet);  
}

File Result

It returns different file format view page using file result

public ActionResult FileDemo()  
{  
      return File("Web.Config", "text");  
}

Content Result

It returns different content’s format to view.

public ActionResult Index()  
{  
      return Content("<script>alert('Content Result');</script>");  
}

Faisal Pathan

Faisal Pathan is a founder of TheCodeHubs, .NET Project Manager/Team Leader, and C# Corner MVP. He has extensive experience with designing and developing enterprise-scale applications. He has good skills in ASP.NET C#, ASP.NET Core, ASP.NET MVC, AngularJS, Angular, React, NodeJS, Amazon S3, Web API, EPPlus, Amazon MWS, eBay Integration, SQL, Entity Framework, JavaScript, eCommerce Integration like Walmart, Tanga, Newegg, Group-on Store, etc. and Windows services.

Share
Published by
Faisal Pathan

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago