我正在使用MVC 4應用程序並在route.config中映射URL 我想使用50個不同的路由名稱爲其運行一個for環路route.config這樣的事情..For Loop無法在MVC4的route.config中工作
for (int i = 1; i <= 50; i++)
{
string routeChildLink = "URLRoute" + i.ToString();
string pathChildLink = menuSubChild.pageid.ToString() + "/" + menu.title.Replace(" ", "_") + "/" + menuChild.title.Replace(" ", "_") + "/" + menuSubChild.title.Replace(" ", "_") + "/" + i;
routes.MapRoute(routeSubChildLink, pathSubChildLink, new { controller = "home", action = "index" });
}
但是當我通過一個錯誤,說明運行站點爲「名爲‘URLRoute1’A路線已經是路由集合中。路線名稱必須是唯一的。」 For循環不起作用。
請幫忙。
感謝
其中'routeSubChildLink','pathSubChildLink'從何而來? – jzm
我沒有收到任何錯誤。讓我知道他們是如何發生的?請發佈完整代碼... –
@jzm:routeSubChildLink是名稱,pathSubChildLink是URL – Shivendra