【发布时间】:2012-03-10 19:43:39
【问题描述】:
我正在开发一个 ASP.NET 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?
-
当我输入localhost:[port]/internal/input/page1 或localhost:[port]/profile/info 时,我得到一个404。我注意到当我输入localhost:[port]/internal/UserProfileInfo 时,我的页面出现了。但是,这不是我想要使用的网址。
-
您可能需要删除现有的默认路由,可能会先匹配
-
“现有默认路由”行会是什么样子?
-
默认 global.asax.cs 中为您添加的 {controller}/{action}/{id} 路由
标签: c# asp.net-mvc-3 routing controller