2017-03-16 96 views
1

我已将两个应用程序之间共享的代码移除到包含控制器的共享项目中。我得到“多种类型被发现,匹配控制器名为”错误。我不知道为什么会发生这种情况。所以这是我的共享控制器项目之间的MVC共享项目找到控制器的多种类型

namespace App.Web.Shared.Controllers 
{ 
    public class ParkingTicketController : BaseController 
    { 
    public ParkingTicketController(ServiceLocator serviceLocator) : base(serviceLocator) 
    { 
    } 

    /// <summary> 
    /// Views the specified identifier. 
    /// </summary> 
    /// <param name="publicId">The public identifier.</param> 
    /// <returns></returns> 
    [AuthorizeAccess(Roles = ApplicationRoles.None)] 
    public ActionResult Display(string publicId) 
    { 
     //Shared 
    } 
} 
} 


namespace App.Web.Driver.Controllers 
{ 
[AuthorizeAccess(Roles = ApplicationRoles.Driver)] 
public class ParkingTicketController : Shared.Controllers.ParkingTicketController 
{ 
    // 
    // GET: /ParkingTicket/ 

    /// <summary> 
    /// Initializes a new instance of the <see cref="ParkingTicketController"/> class. 
    /// </summary> 
    /// <param name="serviceLocator">The service locator.</param> 
    public ParkingTicketController(ServiceLocator serviceLocator) : base(serviceLocator) 
    { 
    } 
} 

}

这是建立路由。所以应该匹配的驱动程序控制器

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

我只是从我的观点称这是

@Html.ActionLink("View Print", "Display", "ParkingTicket", new { id = Model.ParkingTicket.PublicId }, new { @class = "btn btn-blue" }) 

错误消息

enter image description here

回答

2

如果您不希望您的共享控制器服务任何请求,那么您可以定义要查找的默认名称空间; taken from here

ControllerBuilder.Current.DefaultNamespaces.Clear(); 
ControllerBuilder.Current.DefaultNamespaces.Add("App.Web.Driver.Controllers"); 

而这应该限制任何查找只是你的主命名空间。如果你添加另一个重要的命名空间,那么你必须将它添加到这个列表中。

相关问题