要路由到另一个文件夹,需要在Startup.cs文件中添加以下代码段:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
routes.MapPageRoute("AnotherFolder", "AnotherFolder/{*pathInfo}", "~/AnotherFolder");
});
在以上代码中,我们使用MapPageRoute方法将文件夹“AnotherFolder”映射为路由“/{*pathInfo}”,转到目录“~/AnotherFolder”。这个星号是所谓的通配符。
接下来,在我们要访问的页面中,要使用指向这个路由的URL来指定导航链接或超链接:
Go to Test Page
这可在另一个文件夹中的TestPage.cshtml页面上使用。