What is ActionResult in ASP.NET MVC?
Quick Answer
ActionResult is the base type for what a controller action returns. It represents a deferred command — “render this view”, “return this JSON”, “redirect there”, “send a 404” — that the framework executes after filters run. Helper methods like View(), Json(), RedirectToAction(), NotFound() and Ok() create the specific result types.
ActionResult is the base class for whatever a controller action returns. Instead of writing to the response, the action returns a result object that describes what should happen — render a view, return JSON, redirect, send a 404 — and the framework executes that after the filters have run. You create them with helpers: View(), Json(), RedirectToAction(), NotFound(), Ok(). For the return type I usually use IActionResult when an action has more than one possible outcome, and in Core Web API I use ActionResult<T> so I can return either the object or a status result and still get good Swagger output.
An action doesn't write to the response directly; it returns a result object and the framework executes it. Common types:
ViewResult(View(model)) — renders a Razor view.PartialViewResult— renders a partial, for AJAX fragments.JsonResult(Json(data)) — serialises to JSON.RedirectResult/RedirectToActionResult— 302/301 redirect.StatusCodeResult,NotFoundResult,BadRequestResult,OkObjectResult— bare status codes / with a body.FileResult— streams a file.ContentResult— raw string with a content type.
Return type choices:
IActionResult— the interface; use when an action can return different result types.ActionResult<T>(Core) — lets you return eitherT(serialised) or a result likeNotFound(), and improves API documentation.- A concrete type like
ViewResult— fine when there is only one outcome, and slightly clearer.
Practise the whole thread the way an interviewer walks it — each question builds on the last.
- What is ASP.NET MVC?
- Explain the ASP.NET MVC request life cycle.
- What is routing in ASP.NET MVC?
- What is ActionResult in ASP.NET MVC?You are here
- What is the difference between ViewBag, ViewData and TempData?
- What is a strongly typed view in ASP.NET MVC?
- How does model validation work in ASP.NET MVC?