zoukankan      html  css  js  c++  java
  • System.InvalidOperationException: 找到多个与名为“Home”的控制器匹配的类型。

    一,当项目中存在多个网站报错,而不是新增Area出现这个错误时。应该在RouteConfig这样改:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    
    namespace Houtai.Web.Mobile
    {
        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[] { "Houtai.Web.Mobile.Controllers" }
                );
            }
        }
    }

    二,若是添加Area,造成的错误,则

     public class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
               routes.MapRoute(  
                    "Default", // 路由名称  
                    "{controller}/{action}/{id}", // 带有参数的 URL  
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值  
                    ,  new string[] { "Houtai.Web.Mobile.Controllers" }
                ); 
                  
            }
        }
  • 相关阅读:
    梦断代码阅读笔记之一
    你的灯亮着吗阅读笔记之三
    第二次冲刺第八天
    第二次冲刺第七天
    价格计算
    第二次冲刺第六天
    构建之法阅读笔记06
    第二阶段冲刺第五天
    第二阶段冲刺第四天
    第二阶段冲刺第三天
  • 原文地址:https://www.cnblogs.com/May-day/p/6163984.html
Copyright © 2011-2022 走看看