0
我們正在嘗試爲我們的MVC應用創建兩個視圖。移動和Web管理手機和網絡瀏覽器的路由
這是兩個環節,我們跟着
- Handling routing for both Desktop & Mobile Controllers in one instance of ASP.NET MVC
- Mixing ASP.NET MVC Display Mode Providers and Routing Rules
創建的帳戶/ Login.cshtml頁面和賬戶/ 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 /'開頭,強制路由顯示移動視圖?
或者還有另一種方法嗎?
如果你要在你的URL始終使用移動指定2個路由定義,你可以創建一個名爲mobile的區域將永遠在'http:// siteurl/mobile /' – JamieD77