「FileContentResult クラス (System.Web.Mvc)」の版間の差分
imported>Administrator ページの作成:「FileContentResultクラスとは、ASP.NET MVCのアクション・メソッドの戻り値(ActionResultおよびその派生クラス)として、byte...」 |
imported>Administrator |
||
| (同じ利用者による、間の1版が非表示) | |||
| 1行目: | 1行目: | ||
FileContentResultクラスとは、[[ASP.NET MVC]]の[[アクション・メソッド]]の戻り値([[ActionResult]]およびその派生クラス)として、byte配列の内容をバイナリデータとしてそのまま送信する[[FileResultクラス]]を継承したクラスである。 | FileContentResultクラスとは、[[ASP.NET MVC]]の[[アクション・メソッド]]の戻り値([[ActionResult]]およびその派生クラス)として、byte配列の内容をバイナリデータとしてそのまま送信する[[FileResultクラス]]を継承したクラスである。 | ||
== 使用例 == | |||
<source lang="csharp"> | |||
using System.Web.Mvc; | |||
using System.Text; | |||
public class HomeController : Controller | |||
{ | |||
public ActionResult DownloadCsv() | |||
{ | |||
this.HttpContext.Response.AddHeader( | |||
"Content-Disposition", | |||
"attachment; filename=hello.csv"); | |||
byte[] data = Encoding.UTF8.GetBytes("hello, world"); | |||
return new FileContentResult(data, "text/csv"); | |||
} | |||
} | |||
</source> | |||
== 関連項目 == | == 関連項目 == | ||
2012年4月18日 (水) 11:46時点における最新版
FileContentResultクラスとは、ASP.NET MVCのアクション・メソッドの戻り値(ActionResultおよびその派生クラス)として、byte配列の内容をバイナリデータとしてそのまま送信するFileResultクラスを継承したクラスである。
使用例[編集 | ソースを編集]
using System.Web.Mvc;
using System.Text;
public class HomeController : Controller
{
public ActionResult DownloadCsv()
{
this.HttpContext.Response.AddHeader(
"Content-Disposition",
"attachment; filename=hello.csv");
byte[] data = Encoding.UTF8.GetBytes("hello, world");
return new FileContentResult(data, "text/csv");
}
}
関連項目[編集 | ソースを編集]
- ActionResult - ASP.NET MVCのアクション・メソッドの戻り値として使うベースクラス。
- FileResult - ファイルをダウンロードさせるためのベースクラス。
- FileContentResult - バイト配列をHTTPレスポンスに書き込む。
- FilePathResult - 指定されたファイルパスの中身をHTTPレスポンスに書き込む。
- FileStreamResult - Streamクラスの中身をHTTPレスポンスに書き込む。
- FileResult - ファイルをダウンロードさせるためのベースクラス。
- ASP.NET MVC