我已将两个应用程序之间共享的代码删除到包含控制器的共享项目中。我得到"发现多个类型匹配名为&#34的控制器;错误。我不确定为什么会这样。所以这是我的共享控制器
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" })
错误消息
答案 0 :(得分:2)
如果您不希望共享控制器提供任何请求,那么您可以定义要查看的默认命名空间; taken from here:
ControllerBuilder.Current.DefaultNamespaces.Clear();
ControllerBuilder.Current.DefaultNamespaces.Add("App.Web.Driver.Controllers");
这应该将任何查找限制在您的主命名空间。如果添加另一个重要的命名空间,则必须将其添加到此列表中。