ASP.NET MVC基础页面跳转问题

4677人阅读 2021/3/11 11:32 总访问:651611 评论:0 收藏:0 手机
分类: Csharp

MVC 页面跳转


  前  言

tnblog

 M V C  是通过控制器来访问页面的


本视图内跳转

 public ActionResult News()
        {
            //打开本视图,名称为News.cshtml
            return View();
        }
        
        public ActionResult News2()
        {
            //跳转到本视图Index.cshtml  (浏览器地址会发生变化)
            return RedirectToAction("Index");
        }
        
         public ActionResult News3()
        {
            //跳转到本视图ActionResult Index() (浏览器地址不会发生变化)
            return View("Index");
        }

本视图外跳转

    public ActionResult News2()
        {
            //跳转到视图Game文件夹 的 Index.cshtml  (浏览器地址会发生变化)
            return RedirectToAction("Index","Game");
        }
        
        
     public ActionResult Game()
        {
            //跳转到视图/Game文件夹/Index.cshtml  (浏览器地址不会发生变化)
            return View("~/Views/Game/Index.cshtml");
        }


评价
脚踏实地,一步一个脚印
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术