【发布时间】:2016-08-01 19:27:53
【问题描述】:
我们正在尝试为我们的 MVC 应用程序创建两个视图。移动和网络
这是我们关注的两个链接
- Handling routing for both Desktop & Mobile Controllers in one instance of ASP.NET MVC
- Mixing ASP.NET MVC Display Mode Providers and Routing Rules
创建了 Account/Login.cshtml 页面和 Account/Login.Mobile.cshtml 页面(具有不同的布局)。创建了默认路由
routes.MapRoute(
name: "DefaultMobile",
url: "mobile/{controller}/{action}/{id}",
defaults: new
{
mobile = true,
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
但问题是我们正在使用routes.MapMvcAttributeRoutes(); 并生成像\login 这样的网址。有没有办法强制mobile/login 获取移动视图。如果 url 以“/mobile/”开头,会强制路由显示移动视图吗?
或者有其他方法吗?
【问题讨论】:
-
如果您要始终在您的网址中使用手机,您可以创建一个名为手机的区域,该区域将始终位于
http://siteurl/mobile/
标签: asp.net-mvc routing