码迷,mamicode.com
首页 > Web开发 > 详细

mvc view返回值

时间:2018-12-25 11:26:12      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:red   view   script   ctr   ret   str   代码   ica   demo   

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

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

        public FileResult Index()
        {
            return File(Server.MapPath("~/demo.jpg"), "application/x-jpg", "demo.jpg");        //浏览器直接下载demo.jpg   
        }

        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大致相同
        }

 

mvc view返回值

标签:red   view   script   ctr   ret   str   代码   ica   demo   

原文地址:https://www.cnblogs.com/ganzhihui/p/10172448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!