ASP.NET MVC中Controller的使用Demo
来源:互联网 发布:网络语拉仇恨什么意思 编辑:程序博客网 时间:2024/06/04 19:18
ActionResult是ContentResult类、ViewResult类、JsonResult类等所有的Controller中返回值类型的基类
ASP.NET MVC中Controller的使用Demo
using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Mvc.Ajax;using System.IO;namespace DemoRC.Controllers{ public class DemoController : Controller { /// <summary> /// http://localhost:1847/Demo/ContentResultDemo /// </summary> /// <returns></returns> public ActionResult ContentResultDemo() { string contentString = "ContextResultDemo! 请查看 Controllers/DemoController.cs文件,里面包含所有类型ActionResult的用法."; return Content(contentString); } /// <summary> /// http://localhost:1847/Demo/EmptyResultDemo /// </summary> /// <returns></returns> public ActionResult EmptyResultDemo() { return new EmptyResult(); } /// <summary> /// http://localhost:1847/Demo/FileContentResultDemo /// </summary> /// <returns></returns> public ActionResult FileContentResultDemo() { FileStream fs = new FileStream(Server.MapPath(@"/resource/Images/1.gif"), FileMode.Open, FileAccess.Read); byte[] buffer = new byte[Convert.ToInt32(fs.Length)]; fs.Read(buffer, 0, Convert.ToInt32(fs.Length) ); return File(buffer, @"image/gif"); } /// <summary> /// http://localhost:1847/Demo/FilePathResultDemo /// </summary> /// <returns></returns> public ActionResult FilePathResultDemo() { //可以将一个jpg格式的图像输出为gif格式 return File(Server.MapPath(@"/resource/Images/2.jpg"), @"image/gif"); } /// <summary> /// http://localhost:1847/Demo/FileStreamResultDemo /// </summary> /// <returns></returns> public ActionResult FileStreamResultDemo() { FileStream fs = new FileStream(Server.MapPath(@"/resource/Images/1.gif"), FileMode.Open, FileAccess.Read); return File(fs, @"image/gif"); } /// <summary> /// http://localhost:1847/Demo/HttpUnauthorizedResultDemo /// </summary> /// <returns></returns> public ActionResult HttpUnauthorizedResultDemo() { return new HttpUnauthorizedResult(); } /// <summary> /// http://localhost:1847/Demo/JavaScriptResultDemo //mvc ajax脚本引入才会起作用 /// </summary> /// <returns></returns> public ActionResult JavaScriptResultDemo() { return JavaScript(@"alert(""Test JavaScriptResultDemo!"")"); } /// <summary> /// http://localhost:1847/Demo/JsonResultDemo /// </summary> /// <returns></returns> public ActionResult JsonResultDemo() { var tempObj = new { Controller = "DemoController", Action = "JsonResultDemo" }; return Json(tempObj); } /// <summary> /// http://localhost:1847/Demo/RedirectResultDemo /// </summary> /// <returns></returns> public ActionResult RedirectResultDemo() { return Redirect(@"http://localhost:1847/Demo/ContentResultDemo"); } /// <summary> /// http://localhost:1847/Demo/RedirectToRouteResultDemo /// </summary> /// <returns></returns> public ActionResult RedirectToRouteResultDemo() { return RedirectToAction(@"FileStreamResultDemo"); } /// <summary> /// http://localhost:1847/Demo/PartialViewResultDemo /// </summary> /// <returns></returns> public ActionResult PartialViewResultDemo() { return PartialView(); } /// <summary> /// http://localhost:1847/Demo/ViewResultDemo /// </summary> /// <returns></returns> public ActionResult ViewResultDemo() { //如果没有传入View名称, 默认寻找与Action名称相同的View页面. return View(); } }}</span>
0 0
- ASP.NET MVC中Controller的使用Demo
- Asp.net Mvc Framework可以在Controller中使用的Url.Action方法
- Asp.net Mvc Framework可以在Controller中使用的Url.Action方法
- ASP.NET MVC 中 当前controller、action的获取
- ASP.NET MVC Controller 中访问 Application
- ASP.NET MVC Controller的激活机制
- ASP.NET MVC Controller的激活
- ASP.NET MVC Controller的激活
- ASP.Net MVC中 Echarts简单Demo
- Asp.net MVC 中Ajax的使用
- ASP.NET MVC中DROPDOWNLIST的使用
- ASP.NET MVC中DropDownList的使用
- Spring.Net在ASP.NET MVC的过滤器Controller中无效
- asp.net MVC Controller 小记
- Asp.net MVC Controller学习
- Asp.net MVC 中Controller返回值类型ActionResult
- ASP.NET MVC中创建Controller时序图
- 在ASP.NET MVC 中获取当前URL、controller、action
- hdu 3709 Balanced Number (数位dp)
- 零资源!如何推广一款新的App?
- IOS中Json解析的四种方法
- 2016 数据的交换输出
- 最大公共子字符串和最长公共子序列
- ASP.NET MVC中Controller的使用Demo
- tomcat出现的PermGen Space问题
- hbase 线程处理
- 3D SLicer中图像分割与配准的具体思路
- warning: directory not found for option ' '
- 计算机网络(三)
- 枚举算法
- rsyslog的relp转发及自定义端口号问题
- 2017 字符串统计