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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM