ASPNET MVC3技术要点(15)

发布时间:2021-06-06

ASPNET MVC3技术要点

new Appointment { ClientName = "Joe", Date = DateTime.Parse("1/1/2012")}, new Appointment { ClientName = "Joe", Date = DateTime.Parse("2/1/2012")}, new Appointment { ClientName = "Joe", Date = DateTime.Parse("3/1/2012")}, new Appointment { ClientName = "Jane", Date = DateTime.Parse("1/20/2012")}, new Appointment { ClientName = "Jane", Date = DateTime.Parse("1/22/2012")}, new Appointment {ClientName = "Bob", Date = DateTime.Parse("2/25/2012")}, new Appointment {ClientName = "Bob", Date = DateTime.Parse("2/25/2013")} };

if (!string.IsNullOrEmpty(id) && id != "All") {

data = data.Where(e => e.ClientName == id); }

var formattedData = data.Select(m => new {

ClientName = m.ClientName, Date = m.Date.ToShortDateString() });

return Json(formattedData, JsonRequestBehavior.AllowGet); }

3.2.5 输出文件或二进制数据

3.2.5.1 发送一个文件

public FileResult AnnualReport() {

string filename = @"h:\QS_Chinese.pdf"; string contentType = "application/pdf"; string downloadName = "QS_Chinese.pdf"; return File(filename, contentType, downloadName); }

3.2.5.2 发送一个字节数组

public FileContentResult DownloadReport() {

byte[] data = ... // Generate or fetch the file contents somehow return File(data, "application/pdf", "AnnualReport.pdf"); }

3.2.5.3 发送一个流的内容

public FileStreamResult DownloadReport(){

Stream stream = ...open some kind of stream... return File(stream, "text/html"); }

3.2.6 返回错误和HTTP代码

public HttpStatusCodeResult StatusCode() {

return new HttpStatusCodeResult(404, "URL cannot be serviced"); }

3.3 过滤应用

MVC框架支持四种不同类型的过滤器

ASPNET MVC3技术要点(15).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219