ActionResult

ActionResult可以返回的不仅仅只有一个视图 view()

 

 public ContentResult Index()
        {
            return Content("测试");       //浏览器显示测试
        }

        public EmptyResult Index()
        {
            return new EmptyResult();     //浏览器显示空白            
        }

        public FileResult Index()
        {
            return File("~/Content/demo.mp3", "audio/mp3"); 
        }//浏览器直接下载demo.mp3   //File(路径,类型)

        public HttpNotFoundResult Index()
        {
            return HttpNotFound();     //报404错误          
        }

        public HttpUnauthorizedResult Index()
        {
            return new HttpUnauthorizedResult();     //未授权的页面,跳转到/Account/LogOn          
        }

        public JavaScriptResult hello()
        {
            string js = "alert('你还好吗?');";
            return JavaScript(js);      //页面显示 alert('你还好吗?');} 并不会执行这个js,要执行这个js可以在任意视图里<script src="@Url.Action("hello")" type="text/javascript"></script>     
        }

        public JsonResult Index()
        {
            var jsonObj = new
            {
                Id = 1,
                Name = "小铭",
                Sex = "男",
                Like = "足球"
            };

            return Json(jsonObj, JsonRequestBehavior.AllowGet);     //返回一个JSON,可以将此代码输出到JS处理展示
        }

        public RedirectResult Index()
        {
            return Redirect("~/demo.jpg");      //可以跳转到任意一个路径
            return Redirect("http://www.baidu.com");
            return Redirect("/list");
        }

        public RedirectToRouteResult Index()
        {
            return RedirectToRoute(     //跳转到指定Action
            new
            {
                controller = "Home",
                action = "GetName"
            });
        }

        public ViewResult Index()
        {
            return View();          //这个是最常用的,返回指定视图
            //return View("List");
            //return View("/User/List");
        }

        public PartialViewResult Index()
        {
            return PartialView();          //部分视图,可以作为一个部分引入另外一个视图中,跟View大致相同
        }

https://www.cnblogs.com/kissdodog/archive/2013/01/07/2850334.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值