I know what is causing it ... T4MVC creates a duplicate Index() which is confusing the Umbraco.Web.Mvc.RenderActionInvoker.FindAction() call since there are now two Index() actions. However, the T4MVC action is marked with the `[NonAction]` attributea dn s should be ignored by Umbraco's RendeActionInvoker - but it isn't.
But how do I fix this? The only thing I can think of is to introduce a custom RenderActionInvoker that ignores methods with such an attribute but then I would also need to override the default ControllerFactory too.
Any ideas? There must be projects using T4MVC in Umbraco successfully.
public class CustomControllerFactory : RenderControllerFactory
{
public override IController CreateController(RequestContext requestContext, string controllerName)
{
var instance = base.CreateController(requestContext, controllerName);
var controllerInstance = instance as Controller;
if (controllerInstance != null)
{
controllerInstance.ActionInvoker = new CustomRenderActionInvoker();
}
return instance;
}
}
and
public class CustomRenderActionInvoker : ControllerActionInvoker
{
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName)
{
var ad = base.FindAction(controllerContext, controllerDescriptor, actionName);
if (ad == null)
{
if (controllerContext.Controller is RenderMvcController)
{
return new ReflectedActionDescriptor(
controllerContext.Controller.GetType().GetMethods().First(x =>
x.Name == "Index" &&
!x.GetCustomAttributes(typeof(NonActionAttribute), false).Any()),
"Index",
controllerDescriptor
);
}
}
return ad;
}
}
These are essentially just modified duplicates of what already exists in the Umbraco source.
Thanks for posting that code. The current documentation isn't valid in that this still (v7.0.3) generates an ambiguous error when following the guide with regards to route hijacking and inheriting form RenderModel.
"Ambiguous match found" using T4MVC, Umbraco 6 and hijacking routes
In my current Umbraco 6 build, I am using T4MVC and when I hijack a route I get the following exception:
I know what is causing it ... T4MVC creates a duplicate Index() which is confusing the Umbraco.Web.Mvc.RenderActionInvoker.FindAction() call since there are now two Index() actions. However, the T4MVC action is marked with the `[NonAction]` attributea dn s should be ignored by Umbraco's RendeActionInvoker - but it isn't.
But how do I fix this? The only thing I can think of is to introduce a custom RenderActionInvoker that ignores methods with such an attribute but then I would also need to override the default ControllerFactory too.
Any ideas? There must be projects using T4MVC in Umbraco successfully.
Sounds like it needs to be fixed in the core, created an issue : http://issues.umbraco.org/issue/U4-3675
Ok, yes I have a solution but you have to:
Thanks for posting that code. The current documentation isn't valid in that this still (v7.0.3) generates an ambiguous error when following the guide with regards to route hijacking and inheriting form RenderModel.
If you want to use this with the Hybrid framework (as I recently did), change the conditional line to read:
This is fixed in 6.2/7.1
Awesome, thanks Shannon.
is working on a reply...