ViewResult vs. ActionResult

Karim Samir
SimplifyInterview
Published in
May 21, 2024

ActionResult is an abstract class for all action result types in ASP.NET MVC, so is more general

ViewResult derives from ActionResult. Like others: JsonResult and PartialViewResult …

// OK
public ActionResult Index()
{
return Json(new { foo = "bar", baz = "Blech" });
}
// OK
public ActionResult Index()
{
return View(new { foo = "bar", baz = "Blech" });
}
// KO
public JsonResult Index()
{
return View(new { foo = "bar", baz = "Blech" });
}
// OK
public JsonResult Index()
{
return Json(new { foo = "bar", baz = "Blech" });
}
// OK
public ViewResult Index()
{
return View(new { foo = "bar", baz = "Blech" });
}

--

--