【问题标题】:Multiple types were found that match at different area发现多种类型在不同区域匹配
【发布时间】:2020-10-31 06:18:26
【问题描述】:

当用户点击它时,我有下面的链接,它应该是加载当前区域中的文章视图。 图片

但是当我点击这个链接时,我得到了这个错误

但我已经检查了我的路由配置和管理区域,并且我也使用了命名空间。 在我的路由配置中 在我的管理区域

我不知道是什么问题,我使用了命名空间,但它不起作用。

当我点击这个链接<a href="/Article/Details/2"> 我得到了错误,但我的路由配置像这样 在我的路由配置中:

        routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                    namespaces: new[] { "IdentitySample.Controllers" }
            );

在管理区域配置中:

       public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "Administrator_default",
                "Administrator/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                 new[] { "tadvinhesab.Areas.Administrator.Controllers" }

            );
   
        }

我最终得到了这个链接

   <a  href="@Url.Action("Details", "Article", new {  Area = "IdentitySample",id = @article.id }, "https")">

但是Area = "IdentitySample" 导致当我放入新数组时链接不起作用。 在另一个镜头中,我以这种方式改变了它 &lt;a href="@Url.Action("Details", "Article", new { Area = "", id = @article.id})" class="myCssClass"&gt;link text&lt;/a&gt; 但我的问题还是一样

【问题讨论】:

  • 复制粘贴代码,请勿截图,我们很难通过。

标签: c# asp.net-mvc namespaces


【解决方案1】:

经过几个小时的工作,我终于意识到我使用了默认命名空间为 identitySmaple 的标识示例项目,但在我的项目的某些部分中,我使用了自己的命名空间,其名称与 identitySmaple 不同,这导致了这种奇怪问题。

在 (Ctrl+Shift+H) 的帮助下,我将所有 identitySmaples 替换为我的命名空间,然后它可以正常工作。

【讨论】:

    【解决方案2】:

    您好像忘记更改命名空间了:

    namespaces: new[] { "IdentitySample.Controllers" }
    

    你应该把它改成这样:

    namespaces: new[] { "tadvinhesab.Controllers" }
    

    同样在这个链接中,你可以看到很多其他可能的解决方案来解决这个问题:

    Multiple types were found that match the controller named 'Home'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 2015-02-08
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多