IntroductionAn ActionResult is a return type of a controller method in MVC. Action methods help us to return models to views, file streams, and also redirect to another controller's Action method. There are many derived ActionResult types in MVC that you may use to return the results of a controller method; these are more specific for a particular view. All Action Result Classes are derived from "ActionResult". In other words ActionResult is an abstract class that has several subtypes.ViewResultIt renders a specified view to the response stream. The "ViewResult" class inherits from the abstract class "ViewResultBase" and is used to render a view. This class contains methods for finding the view to render and also for executing the result. This class also contains properties that identify the view (view Name) to render for the application.public ViewResult ViewResultTest(){ return View("ViewResultTest");}http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.view.aspxPartialViewResultThe PartialViewResult class is inherited from the abstract "ViewResultBase" class and is used to render a partial view. This class contains methods for finding the partial view to render and also for executing the result. This class also contains properties that identify the partial view (View Name) to render for the application. PartialViews are not common as action results. PartialViews are not the primary thing being displayed to the user, which is the View. The partial view is usually a widget or something else on the page.public PartialViewResult PartialViewResultTest(){ return PartialView("PartialViewResult");}RedirectResultIt is used to perform an HTTP redirect to a given URL. This class is inherited from the "ActionResult" abstract class.public ActionResult RedirectResultTest(){ return Redirect("http://www.google.com/");} public RedirectResult RedirectResultTest(){ return Redirect("http://www.google.com/");}http://msdn.microsoft.com/en-us/library/system.web.mvc.redirectresult.aspx
RedirectToRouteResultRedirectToResult is used to redirect by using the specified route values dictionary. This class is inherited from the "ActionResult" abstract class.public ActionResult RedirectToRouteResultTest(int? Id){ return new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { controller = "Home", action = "List", Id = new int?() }));}http://msdn.microsoft.com/en-us/library/system.web.mvc.redirecttorouteresult.aspxContentResultThe ContentResult may be used to return to an action as plain text. This class is inherited from the "ActionResult" abstract class. public ActionResult ContentResultTest(){ return Content("Hello My Friend!");} public ContentResult ContentResultTest(){ return Content("Hello My Friend!");}JsonResultAction methods on controllers return JsonResult (JavaScript Object Notation result) that can be used in an AJAX application. This class is inherited from the "ActionResult" abstract class. Here Json is provided one argument which must be serializable. The JSON result object that serializes the specified object to JSON format.public JsonResult JsonResultTest(){ return Json("Hello My Friend!");}http://msdn.microsoft.com/en-us/library/system.web.mvc.jsonresult(v=vs.98).aspx
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: