When the action is finished, the value of the postback is manipulated by the ActionResult category or its derived categories. ActionResult is an abstract class, so ASP. NET MVC itself is a subclass of many different types of actionresult.
ActionResult sub-class and Description:
Common Viewresult used to pass a view, that is, HTML page content;
Partialviewresult a view, but this view is Partialview;
Redirectresult is used to turn Web pages to other URLs;
Emptyresult is used to return a blank page;
Contentresult returns a literal attribute (text content);
Fileresult returns a binary document;
Filecontentresult returns a binary file that can be downloaded;
Filepathresult returns a binary file that can be downloaded and has a path set;
Filestreamresult returns a stream file that can be downloaded;
Jsonresult returns a JSON result;
Javascriptresult returns a JavaScript object.
These are categories that inherit from ActionResult and can also be used as the type of action.
But the return type we often define in the controller is ActionResult, but the returned value is often something else, such as:
1 // 2 // GET:/product/ 3 Public actionresult Index () 4 {5 return View (); 6 }
This is to think that the object returned by the view is Viewresult.
Controller Common method redirect returns the object is Redirectresult;
The object returned by Redirecttoaction is Redirecttoactionresult;
The object returned by Redirecttoroute is Redirecttorouteresult;
The object returned by JSON is Jsonresult;
The object returned by Javascriptresult is Javascriptresult;
Content returns the object is Contentresult;
The object returned by file is Filecontentresult, Filepathresult, Filestreamresult , and so on;
Here are a few examples
Back to Partialview
1 Publicactionresult productlist ()2 {3PRODUCTBLL PRODUCTBLL =NewPRODUCTBLL (httpcontext.application["efconnectionstring"]. ToString ());4 5ienumerable<product> products =productbll.listproducts ();6 7 returnPartialview ("~/views/instock/_products.cshtml", products);8}
Return JSON
1 PublicActionResult Retrieveproduct (intID)2 {3PRODUCTBLL PRODUCTBLL =NewPRODUCTBLL (httpcontext.application["efconnectionstring"]. ToString ());4 5Product Product =productbll.retrieveproduct (ID);6 7 returnJson (product,jsonrequestbehavior.allowget);8}
Back to PDF
1 Publicactionresult loadpdffile ()2 {3 stringPath =@"C:\ZJF\My Team solutions\allure\web\backofficev2\google_merchant_center_ Quick Operation manual. pdf";4FileStream stream =NewFileStream (Path, FileMode.OpenOrCreate, fileaccess.readwrite);5 6 returnFile (Stream,"application/pdf");7}