Eg:
public ActionResult Foo() { if (someCondition) return View(); // returns ViewResult else return Json(); // returns JsonResult }I above example the return type of Foo() is "ActionResult" so now i am not bound to return a specific type of value, i can return a View/Json/PartialView/RedirectResult. If i would have used "ViewResult" then i would be able to return "View" only. So ActionResult provides us facility to take advantage of polimorphism in Type of return.
ActionResult have several subtypes:
a) ViewResult - Renders a specifed view to the response stream
b) PartialViewResult - Renders a specifed partial view to the response stream
c) EmptyResult - An empty response is returned
d) RedirectResult - Performs an HTTP redirection to a specifed URL
e) RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
f) JsonResult - Serializes a given ViewData object to JSON format
g) JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
h) ContentResult - Writes content to the response stream without requiring a view
i) FileContentResult - Returns a fle to the client
j) FileStreamResult - Returns a fle to the client, which is provided by a Stream
k) FilePathResult - Returns a fle to the client
2 comments:
Good post
This is really interesting, You're a very skilled blogger.
I have joined your rss feed and look forward to seeking more of your magnificent post.
Also, I have shared your site in my social networks!
Post a Comment