zoukankan      html  css  js  c++  java
  • ASP.NET MVC3默认提供了11种ActionResult的实现

     
    在System.Web.Mvc命名空间 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();

            }

        }

  • 相关阅读:
    Atitit.android js 的键盘按键检测Back键Home键和Menu键事件
    Atitit  OOCSS vs bem
    Atitit.js模块化 atiImport 的新特性javascript import
    Atitit.css 规范 bem 项目中 CSS 的组织和管理
    Atitit.eclipse git使用
    Atitit jOrgChart的使用  组织架构图css html
    Atitit.java相比c#.net的优点 优缺点  v2 q330
    Atitit.判断元素是否显示隐藏在父元素 overflow
    Atitit.获得向上向下左的右的邻居的方法 软键盘的设计..
    Atitit..css的体系结构
  • 原文地址:https://www.cnblogs.com/ExMan/p/4357746.html
Copyright © 2011-2022 走看看