我正在实现一个具有文件夹系统的系统(用户可以拥有文件夹,每个文件夹中都可以包含文件或文件夹)。我想根据文件夹构建Url。假设用户有一个文件夹'Folder1',其中有另一个文件夹'Folder2'。当我在Folder1中时,我希望Url看起来像'Home / Folder1',当用户点击'Folder1'中的'Folder2'时,Url应该看起来像'Home / Folder1 / Folder2',它可以永远这样: )
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// THIS IS THE LINE I ADDED
routes.MapRoute(
"Home",
"{folderPath}",
new { controller = "Home", action = "Index", folderPath = UrlParameter.Optional }
);
// END OF LINE I ADDED
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = -1 }
);
}
}
我改变了RouteConfig文件,现在我能够拥有'Home / Folder1'和'Home / Folder2',这不是我想要的:/
我希望我能清楚地解释我的问题。如果有人能帮助我,我会很感激。我实际上是在使用MVC4。
答案 0 :(得分:0)
向folderPath添加*:
"{*folderPath}",
但这会使第二条路线变得毫无用处。