【发布时间】:2018-10-18 09:15:47
【问题描述】:
我正在使用 ASP.NET MVC 并尝试创建一个控制器子文件夹。我查看了该网站上的其他帖子并尝试了我在网上找到的内容,但它仍然遇到了这个问题:
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
下面的截图是我在控制器文件夹中创建的子文件夹。
这是我的 View 文件夹的屏幕截图。
这是我在 RouteConfig.cs 文件中尝试的内容
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "AdminSubForder",
url: "admin/{controller}/{action}/{id}",
defaults: new { controller = "HomeAdmin", action = "Index", id = UrlParameter.Optional }
);
}
但我的子文件夹仍然无法使用。我在这里做错了什么?
【问题讨论】:
-
您必须在 Map.Route 中指定您的控制器命名空间名称,以便它可以找到控制器。参考这篇文章stackoverflow.com/questions/17178688/controller-in-sub-folder 另外,将您的管理路由移到第一个位置,因为路由应该定义最具体到最不具体。
-
@KD 在我的 RouteConfig.cs 文件中吗?
-
我会第一个咬人:除非你有要求,否则不要这样做。停止。你只是在与 MVC 战斗。你没有让它为你的公司或雇主做任何新的事情或增加价值。
标签: c# asp.net asp.net-mvc