zoukankan      html  css  js  c++  java
  • 步步为营:MVC3中默认提供了11种ActionResult的实现

    在System.Web.Mvc命名空间
    ActionResult
    ContentResul
    EmptyResult
    FileResult
    HttpStatusCodeResult
    HttpNotFoundResult
    HttpUnauthorizedResult
    JavaScriptResult
    JsonResult
    RedirectResult
    RedirectToRouteResult
    ViewResultBase
    PartialViewResult&nbsp
    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();
    }
    }



  • 相关阅读:
    element-ui 设置input的只读或禁用
    vue 获取后端数据打印结果undefined问题
    用yaml来编写配置文件
    [LeetCode] 28. 实现strStr()
    [LeetCode] 25. k个一组翻转链表
    [LeetCode] 26. 删除排序数组中的重复项
    [LeetCode] 24. 两两交换链表中的节点
    [LeetCode] 23. 合并K个排序链表
    [LeetCode] 21. 合并两个有序链表
    [LeetCode] 22. 括号生成
  • 原文地址:https://www.cnblogs.com/79039535/p/2419223.html
Copyright © 2011-2022 走看看