我想要什么?
我正在尝试覆盖ItemController的Display方法(Orchard.Core.Contents.Controllers.ItemController),因此我可以根据Accept Header更改输出。
我做了什么?
我已经制作了ItemController的副本并将其放在我的自定义模块的Controller文件夹中。还在类上面添加了OrchardSuppressDependency属性。
[OrchardSuppressDependency("Orchard.Core.Contents.Controllers.ItemController")]
[Themed]
public class ItemController : Controller
{
private readonly IContentManager _contentManager;
public ItemController(IContentManager contentManager, IShapeFactory shapeFactory, IOrchardServices services)
{
_contentManager = contentManager;
Shape = shapeFactory;
Services = services;
T = NullLocalizer.Instance;
}
dynamic Shape { get; set; }
public IOrchardServices Services { get; private set; }
public Localizer T { get; set; }
// /Contents/Item/Display/72
public ActionResult Display(int id)
{
var contentItem = _contentManager.Get(id, VersionOptions.Published);
if (contentItem == null)
return HttpNotFound();
if (!Services.Authorizer.Authorize(Permissions.ViewContent, contentItem, T("Cannot view content")))
{
return new HttpUnauthorizedResult();
}
//@Todo change output
dynamic model = _contentManager.BuildDisplay(contentItem);
return View((object)model);
}
结果
ShellRoute.cs中显示错误
{"The controller for path '/OrchardLocal/products/product-2' was not found or does not implement IController."}
栈跟踪
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at Orchard.Mvc.OrchardControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) in XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\src\Orchard\Mvc\OrchardControllerFactory.cs:line 76
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at Orchard.Mvc.Routes.ShellRoute.HttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) in XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\src\Orchard\Mvc\Routes\ShellRoute.cs:line 148
我忽略了什么吗? 或者这是错误的做法?