ASP.NET MVC3默认提供了11种ActionResult的实现(简单用法)
来源:互联网 发布:七月十五插件数据下载 编辑:程序博客网 时间:2024/05/19 19:30
ActionResult
ContentResult
EmptyResult
FileResult
HttpStatusCodeResult
HttpNotFoundResult
HttpUnauthorizedResult
JavaScriptResult
JsonResult
RedirectResult
RedirectToRouteResult
ViewResultBase
PartialViewResult
ViewResult
示例代码:
public class ActionResultController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult ContentResult()
{
return Content("Hi, 我是ContentResult结果");
}
public ActionResult EmptyResult()
{
//空结果当然是空白了!
//至于你信不信, 我反正信了
return new EmptyResult();
}
public ActionResult FileResult()
{
var imgPath = Server.MapPath("~/demo.jpg");
return File(imgPath, "application/x-jpg", "demo.jpg");
}
public ActionResult HttpNotFoundResult()
{
return HttpNotFound("Page Not Found");
}
public ActionResult HttpUnauthorizedResult()
{
//未验证时,跳转到Logon
return new HttpUnauthorizedResult();
}
public ActionResult JavaScriptResult()
{
string js = "alert(\"Hi, I'm JavaScript.\");";
return JavaScript(js);
}
public ActionResult JsonResult()
{
var jsonObj = new
{
Id = 1,
Name = "小铭",
Sex = "男",
Like = "足球"
};
return Json(jsonObj, JsonRequestBehavior.AllowGet);
}
public ActionResult RedirectResult()
{
return Redirect("~/demo.jpg");
}
public ActionResult RedirectToRouteResult()
{
return RedirectToRoute(new {
controller = "Hello", action = ""
});
}
public ActionResult ViewResult()
{
return View();
}
public ActionResult PartialViewResult()
{
return PartialView();
}
//禁止直接访问的ChildAction
[ChildActionOnly]
public ActionResult ChildAction()
{
return PartialView();
}
//正确使用ChildAction
public ActionResult UsingChildAction()
{
return View();
}
}
- ASP.NET MVC3默认提供了11种ActionResult的实现(简单用法)
- ASP.NET MVC3默认提供了11种ActionResult的实现
- ASP.NET MVC3默认提供了11种ActionResult的实现
- 目前ASP.NET MVC3默认提供了11种ActionResult的实现
- ActionResult的实现(2)-mvc3
- asp.net mvc3 简单的文件上传下载
- ASP.NET MVC3的伪静态实现
- ASP.NET MVC3的伪静态实现
- asp.net mvc3的静态化实现
- Asp.Net Mvc3 修改视图的默认路径
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- ASP.NET MVC几种ActionResult的本质:FileResult
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- ASP.NET MVC3 让依赖注入来的更简单(新补充了Ninject示例)
- asp.net mvc3中母版页+局部刷新的用法
- asp.net MVC3 + JQuery 的ajax简单使用
- android 自定义视图——onMeasure,MeasureSpec源码 流程 思路详解
- 安卓权限大全
- s3c2440 与LCD的浅析
- QT Layout源码解析
- tomcat报空指针
- ASP.NET MVC3默认提供了11种ActionResult的实现(简单用法)
- SpringMVC入门学习(二)应用注解方式+注解优化
- log4j日志配置——Console+Database+E-Mail
- LEETCODE: Remove Duplicates from Sorted List
- 在ubuntu上创建scrapy爬虫
- TFT LCD
- [C++]_[初级]_[删除字符串中的前后空格]
- ie8下bootstrap3的Glyphicons图标不显示问题
- CocoaPods安装和使用