VS2022 新建 MVC,页面(跳转)ACTION总结
测试新页面打开
-
新建项目
-
新建控制器
-
新建页面
.net mvc 的页面跳转总结:
同样控制器内的action跳转
不同控制器内的action跳转
有参数的action跳转
无参数的action跳转
1.RedirectToAction(“Index”);//一个参数,在本Controller下,不传入参数。
2.RedirectToAction(ActionName,ControllerName) //可直接跳转到别的Controller.
3.RedirectToRoute(new {controller=“Home”,action=“Index”});//可跳转到其他controller
4.RedirectToRoute(new {controller=“Home”,action=“Index”, id=param});//可跳到其他controller,带参数。
5.Response.Redirect(“Index?id=1”);//用于本controller下的方法名称,可带参数。
6.return Redirect(“Index”);//用于本controller下的方法名称。
7.return View(“Index”); //直接显示对应的页面 不经过执行Controller的方法。
8.return View("~/Views/Home/Index.aspx");//这种方法是写全路径,直接显示页面,不经过Controller方法
9.return View();//直接显示页面,不经过Controller方法