「ActionResult クラス (System.Web.Mvc)」を編集中
ナビゲーションに移動
検索に移動
この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
1行目: | 1行目: | ||
− | ActionResult クラスとは、[[ASP.NET MVC]] | + | ActionResult クラスとは、[[ASP.NET MVC]]のアクション・メソッドの戻り値として使う各種クラス(ActionResultを継承したクラス)のベースクラス。 |
− | + | アクションメソッド内でActionResult(を継承したクラス)の中身を穴埋めしてやると、ASP.NET MVCのフレームワーク側でその内容に従い[[HTML]]や[[JSON]]などのHTTPレスポンスが生成される。 | |
− | + | たとえばViewResultであればビュー(HTMLテンプレート)を呼び出してレンダリングしたり、FileResultであればファイルを指定するだけでフレームワーク側で適切なHTTPレスポンスヘッダを生成し簡単にダウンロードダイアログを表示したりできる。 | |
− | + | ContentResultだけでを用いてゴリゴリ書けば20世紀のPerlで書かれたウェブアプリケーションばりのソースコードになること受けあい。困ったらContentResult。まじおすすめ。 | |
== ActionResultの種類 == | == ActionResultの種類 == | ||
14行目: | 14行目: | ||
** [[FileContentResult]] - バイト配列をHTTPレスポンスに書き込む。 | ** [[FileContentResult]] - バイト配列をHTTPレスポンスに書き込む。 | ||
** [[FilePathResult]] - 指定されたファイルパスの中身をHTTPレスポンスに書き込む。 | ** [[FilePathResult]] - 指定されたファイルパスの中身をHTTPレスポンスに書き込む。 | ||
− | ** [[FileStreamResult]] - | + | ** [[FileStreamResult]] - Streamクラスの中身をHTTPレスポンスに書き込む。 |
* [[HttpUnauthorizedResult]] - 認証要求を送信する。 | * [[HttpUnauthorizedResult]] - 認証要求を送信する。 | ||
* [[JavaScriptResult]] - [[JavaScript]](文字列)を直接HTTPレスポンスに書き込む。 | * [[JavaScriptResult]] - [[JavaScript]](文字列)を直接HTTPレスポンスに書き込む。 | ||
22行目: | 22行目: | ||
* [[PartialViewResult]] - 指定されたビューをレンダリングして、HTMLフラグメント(htmlタグやbodyタグのないAJAX差込用のHTMLパーツ)として送信する。 | * [[PartialViewResult]] - 指定されたビューをレンダリングして、HTMLフラグメント(htmlタグやbodyタグのないAJAX差込用のHTMLパーツ)として送信する。 | ||
* [[ViewResult]] - 指定されたビューをレンダリングして送信する。通常はこれ。 | * [[ViewResult]] - 指定されたビューをレンダリングして送信する。通常はこれ。 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
=== 独自ActionResult === | === 独自ActionResult === | ||
47行目: | 42行目: | ||
public ImageFormat ImageFormat { get; set; } | public ImageFormat ImageFormat { get; set; } | ||
− | private readonly Dictionary<ImageFormat, string> ContentTypes = | + | private readonly Dictionary<ImageFormat, string> ContentTypes = new Dictionary<ImageFormat, string>() |
− | + | { | |
− | + | {ImageFormat.Bmp , "image/bmp"}, | |
− | + | {ImageFormat.Gif , "image/gif"}, | |
− | + | {ImageFormat.Icon, "image/vnd.microsoft.icon"}, | |
− | + | {ImageFormat.Jpeg, "image/jpeg"}, | |
− | + | {ImageFormat.Png , "image/png"}, | |
− | + | {ImageFormat.Tiff, "image/tiff"}, | |
− | + | {ImageFormat.Wmf , "image/wmf"}, | |
− | + | }; | |
− | |||
public override void ExecuteResult(ControllerContext context) | public override void ExecuteResult(ControllerContext context) | ||
81行目: | 75行目: | ||
== 関連項目 == | == 関連項目 == | ||
− | |||
* [[ASP.NET MVC]] | * [[ASP.NET MVC]] | ||