.net mvc区域同名controller和action路由配置,首页指定默认主页到区域页面
来源:互联网 发布:鹅绒被和蚕丝被 知乎 编辑:程序博客网 时间:2024/06/05 20:33
RouteConfig
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // routes.MapRoute( // name: "AdminDefault", // url: "", // defaults: new { action = "Index", controller = "Home", id = UrlParameter.Optional }, // namespaces: new string[] { "MVCDemo.Areas.Admin.Controllers" } //); //默认视图查找区域为/Views/ /** * Admin区域action中使用return View("Index1")返回的视图路径/Views/{controller}/Index1.cshtml * 可使用相对路径return View("~/Areas/Admin/Views/Home/Index.cshtml"); */ routes.MapRoute( name: "adminDefault", url: "", defaults: new { area = "Admin", controller = "Home", action = "Index"}, //默认主页 namespaces:new string[] { "MVCDemo.Areas.Admin.Controllers" } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, //默认主页 namespaces: new string[] { "MVCDemo.Controllers" } ); } }AdminAreaRegistration
public class AdminAreaRegistration : AreaRegistration { public override string AreaName { get { return "Admin"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", controller="Home", id = UrlParameter.Optional }, namespaces: new string[] { "MVCDemo.Areas.Admin.Controllers" } ); } }
Areas.Admin.Controllers
namespace MVCDemo.Areas.Admin.Controllers{ public class HomeController : Controller { // GET: Admin/Home public ActionResult Index() { return View("~/Areas/Admin/Views/Home/Index.cshtml"); //return View("Index1"); } }}
访问网站根目录localhost:8080/默认跳转到Admin区域下Home/Index
0 0
- .net mvc区域同名controller和action路由配置,首页指定默认主页到区域页面
- 页面指定区域导入到Excel和world
- .NET在指定区域显示其它页面
- 打印页面指定区域
- asp.net mvc 之 Controller 和 Action
- ASP.NET MVC Controller和Action
- Struts2 首页action/controller配置
- 导出页面指定区域内容到Word/Excel
- javascript 同一个页面转向,显示到指定区域
- vWebPrint打印页面指定区域
- web页面打印指定区域
- shape-指定页面图像区域
- 页面指定区域懒加载
- MVC 3 中的路由以及区域详解
- MVC 如何设定默认默认路由为指定的Area下的某个action
- 单页面多路由区域操作
- asp.net mvc设置area页面为默认路由
- 6a828-视频播放默认播放区域是等比例缩放需要改为自动充满到指定区域
- MYSQL存储过程详解
- 后台系统遇到的坑。。。一定记住以后不要再有这样的错误了
- python基础学习以及3.X和2.X的不同
- LCA 模板
- Otsu自适应阈值算法
- .net mvc区域同名controller和action路由配置,首页指定默认主页到区域页面
- Saving Data in iOS
- 带编号的存储过程
- 第五届省赛题 奇怪的排序
- HashMap的工作原理
- 【JavaScript】2.Http中Get与Post两种请求方式的差异
- 4.流式计算
- 将整型的ASCii码值转换为对应的ASCii码字符串
- 1、RxJava2 & Retrofit2封装实践 简介