主地址:http://localhost:3412/Home/Index

区域地址:http://localhost:3412/T200/Home/Index

 

找到多个与名为“Home”的控制器匹配的类型的解决方案

 

 

解决方法: 注册路由添加命名空间(namespaces)参数 (一定要是正确的)

 

public class RouteConfig
    {
        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 },
                //这里很重要 一定要是正确的 命名空间 否则一样会报错 
                namespaces: new string[] { "Demo.Controllers" }
            );
        }
    }

  

 区域配置也需要修改

public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "T200_default",
                "T200/{controller}/{action}/{id}",
                 new { action = "Index", id = UrlParameter.Optional },
                 new string[] { "Demo.Areas.T200.Controllers" }
            );
        }

  

 

相关文章:

  • 2022-12-23
  • 2022-02-19
  • 2022-01-18
  • 2021-08-04
  • 2021-10-26
  • 2021-10-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案