简体   繁体   中英

Why i'm Getting this Error as Multiple types were found that match the controller named 'Home'

Here I Added Areas in that Area i had taken Men & Womens File in in Both(Men & Women) I have HomeController & its Index when i try to execute the view its Throughing an Error As

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

I Added Files in RouteConfix.cs

namespace Delete
{
    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[] { "MyNamespace.Home", "MyNamespace2.Home" }
            );
        }
    }
}

WomensAreaRegister.cs

   public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "Women_default",
                "Women/{controller}/{action}/{id}",
                new {Controller="Department", action = "Index", id = UrlParameter.Optional },
                      new[] { "MyNamespace.Areas.Admin.Controllers" }
            );
        }

MensAreaRegister.cs

 public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "Men_default",
                "Men/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }, new[] { "MyNamespace2.Areas.Admin.Controllers" }            

            );
        }

please Help me Where im Doing Wrong

Add This in Route.Config defaults: new { controller = "Home", action = "Index", id =

UrlParameter.Optional },
                namespaces: new[] { "ProjectName.Controllers" }

And Add this in Yours Area Controller

 public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Women_default",
            "Women/{controller}/{action}/{id}",
            new {Controller="Home", action = "Index", id = UrlParameter.Optional }
        );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM