0
我正在爲我的MVC應用程序寫幾條路線。我有我的應用程序以下途徑:由於我爲控制器的特定操作編寫了路由,是否需要爲控制器內的所有操作編寫路由?
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Pages", action = "Index", id = UrlParameter.Optional }
);
以上時使用我想訪問喜歡的默認值路徑:
www.servicili.com/budget/edit/1
www.servicili.com/professional/view/234
但是,我創建了以下路線爲特定目的:
routes.MapRoute(
name: "Perfil",
url: "{UsuApelido}",
defaults: new { controller = "Perfil", action = "Index"}
);
以上,用於訪問一個「水暖工」例如的URL輪廓的路線: www.servicili.com/MarkZuckberg
輪廓細節是控制器上PERFIL和行動索引,但是,因爲我寫了這條路線,所有其他行動不起作用。
例如:如果我試圖訪問另一個控制器內指數行動,將其重定向到的指數 PERFIL。
- 問題是:由於我爲控制器的特定操作編寫了路由,是否需要爲控制器內的所有操作編寫路由?在2號位
routes.MapRoute(
name: "Perfil",
url: "{*UsuApelido}",
defaults: new { controller = "Perfil", action = "Index"},
constraints: new { UsuApelido = new PlumberUrlConstraint() }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Pages", action = "Index", id = UrlParameter.Optional }
);
只需要修復代碼並在Constring的最後添加} new:您知道一個鏈接以獲取有關如何在MVC中學習創建路由的更多參考? tks非常多 – Dan
你可以試試[這個鏈接](http://www.asp.net/mvc/overview/controllers-and-routing) –