我正在研究ASP.NET MVC應用程序。出於某種原因,每當我認爲我理解路由時,就會彈出一些我不明白的東西。目前,我有兩條路線,我似乎無法弄清楚。我的目錄結構如下所示MVC路由誤解
- Views
- Internal
- Profile
- Index.cshtml
- Input
- Page1.cshtml
在我的Global.asax.cs文件,我已經添加了以下映射:
routes.MapRoute(
"UserProfileInfo",
"{controller}/profile",
new { controller = "Internal", action = "UserProfileInfo" }
);
routes.MapRoute(
"Page1",
"{controller}/input/page1",
new { controller = "Internal", action = "Page1" }
);
在myController的,我有以下幾點:
public ActionResult UserProfileInfo()
{
return View("~/Views/internal/profile/Index.cshtml");
}
public ActionResult Page1()
{
return View("~/Views/internal/input/Page1.cshtml");
}
我想將我的操作存儲在單個控制器中。我以爲我已經正確設置了一切。但我繼續得到404.我做錯了什麼?
什麼URL給你404? – Simon 2012-02-20 13:12:33
當我衝在http:// localhost:[端口] /內部/輸入/ page1或http:// localhost:[端口] /配置文件/信息我得到一個404.我注意到,當我輸入http:// localhost :[port]/internal/UserProfileInfo我的頁面出現了。但是,這不是我想要使用的網址。 – 2012-02-20 13:40:59
您可能需要刪除現有的默認路由,該路由可能會首先匹配 – Simon 2012-02-20 13:56:54