By default, the Controller actions will return the ActionResult object.We can return various types of results as ActionResult, which will decide how the output needs to render on the browser.
Below table shows the various ActionResult.
Name
|
Framework
Behavior
|
Producing
Method
|
Example
|
Contract
Result
|
Returns
a string literal
|
Content
|
Content(“nilesh”)
|
Empty
Result
|
No
Response
|
||
FileContentResult/FilepathResult/
FileStreamResult
|
Return
the contents of file
|
File
|
File(Server.MapPath(“~/Content/site.css”,”text/css”)
|
RedirectResult
|
Redirects
the client to a new URL
|
Redirect
|
RedirectParmanent(“http://nileshviradiya.blogspot.com”)
|
RedirectToRouteResult
|
Redirect
to another action, or another controller’s action
|
RedirectToRoute/
RedirecttoAction
|
RedirectToAction(“index”,”home”,new
{name=name })
RedirectToRoute(“Default”,
new {controller=”home”,action=”about”})
|
ViewResult
PartialViewResult
|
Response
is the responsibility of a view engine
|
View/PartialView
|
|
JsonResult
|
Returns
data in JSON format
|
Json
|
Json(new
{ Message=”test”, Name =”nilesh”}, JsonRequestBehavior.AllowGet);
|
JavaScriptResult
|
Returns
a script to execute.
|
Javascript
|
|
HttpUnauthorizedResult
|
Returns
an HTTP 403 status
|
No comments:
Post a Comment