我正在开发一个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分。我做错了什么?
发布于 2012-02-20 22:33:46
在对MapRoute的调用中,删除控制器名称中的“控制器”后缀,以创建到名为InternalController的类的映射。在查找匹配的实现时,框架会附加Controller后缀。例如:
routes.MapRoute(
"UserProfileInfo",
"{controller}/profile",
new { controller = "Internal", action = "UserProfileInfo" }
); https://stackoverflow.com/questions/9361610
复制相似问题