ASPNET MVC3技术要点(15)
发布时间:2021-06-06
发布时间: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框架支持四种不同类型的过滤器
上一篇:S3C44B0 学习板使用指南
下一篇:朗文交互英语第二级A2答案