ASP.NET MVC控制器子文件夹 [英] ASP.NET MVC Controller SubFolder

查看:186
本文介绍了ASP.NET MVC控制器子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET MVC并尝试创建控制器子文件夹.我查看了该网站上的其他帖子,并尝试了我在网上可以找到的内容,但是仍然遇到了这个问题:

I am using ASP.NET MVC and trying to create a controller subfolder. I have looked at other post on this site and tried what I was able to find online, but it still running into this issue:

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.

下面的屏幕快照是我在控制器文件夹中创建的子文件夹.

The screenshot below is the subfolder I created in my controller folder.

这是我的查看"文件夹的屏幕截图.

and here is a screenshot of my View folder.

这是我在RouteConfig.cs文件中尝试过的内容

And here is what I tried in my RouteConfig.cs file

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 }
    );
}

但是我的子文件夹仍然不起作用.我在这里做什么错了?

But my subfolder still doesn't work. What am I doing wrong here?

推荐答案

尝试以下操作...

首先按照以下方式定义路由... 路由应从最具体最不具体模式

first define your routing in following manner... The routing should be defined from Most Specific to Least Specific patterns

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                    name: "AdminSubForder",
                    url: "admin/{controller}/{action}/{id}",
                    defaults: new { controller = "HomeAdmin", action = "Index", id = UrlParameter.Optional }
                );
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );


        }

如果仍然无法正常运行,请尝试添加控制器的程序集名称,如以下文章所述..

if it still doesn't work, try to add assembly name of your controller as mentioned in following post.. Controller sub folder

另外,请告诉我们您要输入什么URL才能到达页面.

Also, let us know what URL you are typing to reach the page.

这篇关于ASP.NET MVC控制器子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆