Background
In many forum posts I have read one common question. That is, what are ActionResults in MVC. So this article explains ActionResults of MVC that shows the output to the client. So instead of going into depth on the subject, let us start with an overview.
ActionResult
ActionResult is the abstract class for showing the output to the client in various formats as in the result view returned by the controller. The ActionResult is defined in the controller and the controller returns to the client (the browser).
The following are the subtype or types of Action Results that are present in MVC that are used depending on the output requirement of the client.
In many forum posts I have read one common question. That is, what are ActionResults in MVC. So this article explains ActionResults of MVC that shows the output to the client. So instead of going into depth on the subject, let us start with an overview.
ActionResult
ActionResult is the abstract class for showing the output to the client in various formats as in the result view returned by the controller. The ActionResult is defined in the controller and the controller returns to the client (the browser).
The following are the subtype or types of Action Results that are present in MVC that are used depending on the output requirement of the client.
- ViewResult
- PartialViewResult
- EmptyResult
- RedirectResult
- RedirectToRouteResult
- JsonResult
- JavaScriptResult
- ContentResult
- FileContentResult
- FileStreamResult
- FilePathResult
- ViewResult: returns the view to the client as HTML.
Syntax
- public class EmpController : Controller
- {
- public ActionResult Index()
- {
- return View();
- }
- }
- PartialViewResult: returns the partial view to the response stream, usually the partial view called from the main view. It's the same as a user control in ASP.Net.
Syntax
- public class EmpController : Controller
- {
- public ActionResult Index()
- {
- return PartialView("_Empdetails");
- }
- }
- EmptyResult: this action returns the empty response to the client.
Syntax
- public class EmpController : Controller
- {
- public ActionResult Index()
- {
- return new EmptyResult();
- }
- }
- RedirectResult: redirects to the specified URL, the same as Response.Redirect in ASP.Net.
Syntax
- public class EmpController : Controller
- {
- public ActionResult Index()
- {
- return Redirect("http://www.compilemode.com");
- }
- }
- RedirectToRouteResult: does an HTTP redirection to a URL that is determined by the routing engine, based on given route data.
Syntax
- public class EmpController : Controller
- {
- public ActionResult Index()
- {
- filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new {
- action = "View",
- controller = "EmpController",}));
- }
- }
- JsonResult: serializes a given ViewData object into JavaScript Object Notation (JSON) format.
Syntax
- public class EmpController : Controller
- {
- public JsonResult EmpDet()
- {
- return Json("HI", JsonRequestBehavior.AllowGet);
- }
- }
- JavaScriptResult: returns a piece of JavaScript code that can be executed on the client side.
Syntax
- public class EmpController : Controller
- {
- public virtual JavaScriptResult EmpDet()
- {
- var script = string.Format(@"
- MaxNotificaitonsToShow = {0};
- ItemsPerPage = 5;",
- GlobalSettings.MaxNotificaitonsToShow);
- return JavaScript(script);
- }
- }
- ContentResult: writes the content to the response stream without requiring a view.
Syntax
- public class EmpController : Controller
- {
- public ContentResult PersonInfo()
- {
- return Content("Hi Vithal Wadje");
- }
- }
- FileContentResult: This action returns a file to the client.
Syntax
- public class EmpController : Controller
- {
- public FileResult DailyReport()
- {
- string fileName = @"c:\Vithal Wadje\DailyReport.pdf";
- string contentType = "application/pdf";
- return new FilePathResult(fileName, contentType);
- }
- }
- FileStreamResult: returns a file to the client that is provided by a Stream.
- public class EmpController : Controller
- {
- public ActionResult DownloadFile()
- {
- string Fileinfo =@"c:\Vithal Wadje\DailyReport.txt";
- byte[] data = Encoding.UTF8.GetBytes(Fileinfo );
- return File(data, "text/plain","DailyReport.txt");
- }
- }
- FilePathResult: returns a file result to the client.
Syntax
- public class EmpController : Controller
- {
- public FilePathResult DownloadFile(string file, Guid GuID)
- {
- return File(FileStream, "application/octet-stream", fileName);
- }
- }
Note
This article is only a brief description of ActionResults so beginners can understand. For more details please read my future article.
Summary
My next articles will go into depth about each ActionResult. I hope this article is useful for all readers, if you have any suggestion then please contact me including beginners also.
This article is only a brief description of ActionResults so beginners can understand. For more details please read my future article.
Summary
My next articles will go into depth about each ActionResult. I hope this article is useful for all readers, if you have any suggestion then please contact me including beginners also.


Vithal WadjeTOP 100Posted Sep 22, 2015, 9:47 AM EDT
Thanks sir
DarinPosted Sep 22, 2015, 4:19 AM EDT
Good Job !!
Vithal WadjeTOP 100Posted Jul 28, 2015, 10:44 PM EDT
thanks Sharad sir
Vithal WadjeTOP 100Posted Jul 28, 2015, 10:43 PM EDT
thanks sir
Atul RawatPosted Jul 28, 2015, 10:25 PM EDT
nice article sir
SharadPosted Jul 21, 2015, 8:24 PM EDT
good one...
Vithal WadjeTOP 100Posted Jun 22, 2015, 7:39 AM EDT
Thanks Sibeesh Venu sir
Vithal WadjeTOP 100Posted Jun 22, 2015, 7:38 AM EDT
Thanks Shridhar sir
Sibeesh VenuTOP 100Posted Jun 21, 2015, 8:53 AM EDT
Good one.
Shridhar SharmaPosted Jun 21, 2015, 8:31 AM EDT
Nice reference for ActionResult aspirants :)
Vithal WadjeTOP 100Posted Jun 20, 2015, 10:46 PM EDT
Thanks a lot Santhakumar Munuswamy sir for your huge support on every social media website as wel .Thanks a lot .
Santhakumar MunuswamyPosted Jun 20, 2015, 9:46 PM EDT
Thanks for good work
Vithal WadjeTOP 100Posted Jun 20, 2015, 7:49 PM EDT
Thanks Vidya Vrat Agarwal sir,your comment lot for me
Vithal WadjeTOP 100Posted Jun 20, 2015, 7:48 PM EDT
Thanks Manoj Kulkarni sir
Vidya Vrat AgarwalPosted Jun 20, 2015, 10:34 AM EDT
Good coverage of all Result types. Liked it :)
Manoj KulkarniPosted Jun 20, 2015, 8:07 AM EDT
Nice article. Thank you for sharing