路由没有在C#中的ASP.NET MVC [复制]找到视图页面

问题描述 投票:0回答:1

这个问题已经在这里有一个答案:

This is how my project is structured我只有所谓的“家”的一个领域。我想我的主页是“/首页/门户网站/索引”

这是我的RouteConfig.cs:

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

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

当我运行我的应用程序的方法“索引”中的“门户”被调用。 IIS没有找到我的观点,因为它是搜索“〜/查看/”而不是在“〜/地区/主页/浏览/”我不明白为什么。

TL:DR

本地主机/ <=不工作

本地主机/主页/门户网站/索引<=作品

谢谢阅读

编辑:的Application_Start()

 public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        //Autofac
        ContainerBuilder builder = new ContainerBuilder();
        builder.RegisterControllers(typeof(MvcApplication).Assembly);
        RepositoryBuilder.Register(builder);
        ServiceBuilder.Register(builder);
        new AutofacContainer(builder.Build());
        DependencyResolver.SetResolver(new AutofacDependencyResolver(AutofacContainer.Instance));

        //Automapper
        AutoMapperConfig.Configure();
    }
}
c# asp.net-mvc asp.net-mvc-routing
1个回答
0
投票

您需要Application_Start注册您的地区:

AreaRegistration.RegisterAllAreas();
© www.soinside.com 2019 - 2024. All rights reserved.