手机版

ASPNET MVC3技术要点(15)

时间:2025-07-07   来源:未知    
字号:

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文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)