What is ActionResult and how is it different from others?

The ActionResult class is the base class for all action results. An action result can be of type ViewResult, JsonResult, RedirectResult and so on. Hence, when your action method returns multiple results based on different conditions, ActionResult is the best choice. Since it can return any type of result.

public ActionResult Index(int id) {
	if (id == 1) return View(); // returns simple ViewResult
	else if (id == 2) return Json(new {
		result = "1"
	}, JsonRequestBehavior.AllowGet); // returns JsonResult
	else return RedirectToAction("Login"); // returns to Login Page
}
Tagged , . Bookmark the permalink.

Leave a Reply