我正在開發一個簡單的CRUD應用程序使用ASP MVC 1,將爲多個學生程序跨多個表存儲數據。在這樣做的過程中,我試圖弄清楚如何構建URL以適應每個程序,它們的表格和它們的操作。ASP MVC 1自定義路由的文件夾和子文件夾
例如,這是我想實現的是:
site.com/StudProg1/Participant/Create將是URL方案1
插入了用戶表中的條目爲學生site.com/StudProg2/Course/將作爲學生計劃2的課程表的索引頁的URL
在我嘗試創建自定義路由以適應此情況時,我的Global.asax.cs文件表示爲如下:
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"StudProg1",
"StudProg1/{pageName}/{action}",
new { controller = "StudProg1", pageName="Index", action = "Index" }
);
routes.MapRoute(
"StudProg2",
"StudProg2/{pageName}/{action}",
new { controller = "StudProg2", pageName="Index", action = "Index" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
}
其中pageName應該是表名。毫不奇怪,上述結構不會返回我所瞄準的輸出(即它總是指向StudProg的Index頁面)。
此外,我的文件目錄結構是這樣:
Views StudProg1 Index Participant Index Create StudProg2 Index Courses Index Create
等
我的問題是,我如何能提高我的路線正確實現URL結構我的願望。此外,除了Microsoft ASP.NET開發人員網絡站點之外,有沒有關於自定義路由的好教程?