-
Notifications
You must be signed in to change notification settings - Fork 4
Handler Results
Andrew Bullock edited this page Oct 30, 2017
·
3 revisions
There are many types of IResult
, the most common being ViewResult
, JsonResult
and RedirectResult
.
ViewResults
are best created using the Handler.View()
method.
RedirectResults
are best created using the static methods on RedirectResult
, e.g.:
RedirectResult.SeeOther("/elsewhere");
JsonResults
are best created using its constructor, e.g.
new JsonResult(new { foo = "bar" });
To return a non-200 status code, set it on the IResult
you're returning. You almost never need to talk directly to IResponse
:
var result = View("foo");
result.StatusCode = 418;
return result;
To return cache control headers, set them on the IResult
:
var result = View("foo");
result.CachePolicy = CachePolicy.Private;
result.CacheRevalidation = HttpCacheRevalidation.AllCaches;
result.Expires = DateTime.UtcNow.AddDays(1);
TODO