鏈接生成時代碼位於控制器的Indexx中。 所以鏈路上產生的這種形式urlHelper.RouteUrl未生成正確的URL
Wk/Index/XX/YYYY
URL編碼是
url = urlHelper.RouteUrl("Wk", new { slug});
但我需要的鏈接會以這種形式
Wk/C/XXX
在這裏c是其他行動名字 這是如何實現的。
我的全球ASAX貌似
routes.MapRoute(
"Default", // Route name
"{controller}/{id}", // URL with parameters
new { controller = "Home", action = "Index" , id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Wk", // Route name
"{controller}/{action}/{slug}/{id}", // URL with parameters
new { controller = "Wk", action = "c", slug = "", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Book", // Route name
"{controller}/{id}/{pageNo}", // URL with parameters
new { controller = "Book", action = "Index",id = UrlParameter.Optional,pageNo = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"UserArea", // Route name
"{controller}/{slug}/{id}", // URL with parameters
new { controller = "UserArea", action = "Index", slug = UrlParameter.Optional, id = UrlParameter.Optional } // Parameter defaults
);
方法有很多種。這將取決於你的路線是如何定義的。 –
我需要的鏈接WK/C/ c是動作名稱 我不需要指數作爲行動 在Presend它產生WK /索引 告訴我任何一個方法 – user1006544
請問你的路由定義看起來像在Global.asax中? –