Umbraco 7.3.0 to 7.3.1 error: 'Controller' is ambiguous between the following action methods
After upgrading from 7.3.0 to 7.3.1, all the controllers I declared throw an error:
The current request for action 'Index' on controller type
'DonateController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Index(Umbraco.Web.Models.RenderModel) on
type FEE.Web.App_Code.Controllers.DonateController
System.Web.Mvc.ActionResult Index(Umbraco.Web.Models.RenderModel) on
type Umbraco.Web.Mvc.RenderMvcController
I don't get why this upgrade caused this issue. The code is very simple:
public class DonateController : RenderMvcController
{
public ActionResult Index(RenderModel model)
{
return CurrentTemplate(model);
}
}
Try re-saving your template files, I've had this where I've created templates outside of Umbraco (in Visual Studio) and Umbraco hasn't properly referenced the routing. It looks like maybe the update has dropped that info?
I saw this too but was able to modify my code to resolve it. I'm not sure why it only just started becoming a problem, but I think you can fix this by either adding the 'overrides' keyword to the Index method. Or rename the Index method to be the same as the actual template name, assuming you are route hijacking here?
I had the same problem, and James´ solution worked for my project.
Before:
namespace vuc.Controllers.Mvc{
public class VucNyhedController : VucWebsiteUndersideController{
public ActionResult Index(){
return View(Nyhed.GetFromContent(CurrentPage));
}
}}
after:
namespace vuc.Controllers.Mvc{
public class VucNyhedController : VucWebsiteUndersideController{
public override ActionResult Index(RenderModel model){
return View(Nyhed.GetFromContent(CurrentPage));
}
}}
I'm not sure how your code worked before but it shouldn't have. I imagine there was a bug in the Umbraco pipeline in previous versions that somehow allowed this.
You are getting the error because you have two method calls with the same name in your controller Index. There is a virtual instance in your base controller plus your instance. The framework simply doesn't know which method is the correct one.
James and René are both correct.
Your code should be as follows:
public class DonateController : RenderMvcController
{
public override ActionResult Index(RenderModel model)
{
return CurrentTemplate(model);
}
}
This tells the framework the override virtual Index method with your own version.
Veronica - Renaming the method work as the route handler will look for a method matching the document type name first and you have also removed the duplicate method signature from your code.
The bug is a result of a change to the RenderActionInvoker class. A short term solution is to register a customer controller factory which instantiates the previous version's RenderActionInvoker class.
I'm not sure if anyone is still on this thread but I just ran into this issue when setting up my local site and upgrading from Umbraco 7.2.6 to 7.5.9.
The error message i get is:
The current request for action 'Index' on controller type 'HomePageController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult Index(Umbraco.Web.Models.RenderModel) on type DiamFusion.Web.Controllers.HomePageController
System.Web.Mvc.ActionResult Index(Umbraco.Web.Models.RenderModel) on type Buzz.Hybrid.Controllers.SurfaceRenderMvcController
The code for the "HomePageController" is:
namespace DiamFusion.Web.Controllers
{
public class HomePageController : WebControllerBase
{
[DonutOutputCache(CacheProfile = "FiveMins")]
public override ActionResult Index(RenderModel model)
{
return this.CurrentTemplate<>
Umbraco 7.3.0 to 7.3.1 error: 'Controller' is ambiguous between the following action methods
After upgrading from 7.3.0 to 7.3.1, all the controllers I declared throw an error:
I don't get why this upgrade caused this issue. The code is very simple:
Try re-saving your template files, I've had this where I've created templates outside of Umbraco (in Visual Studio) and Umbraco hasn't properly referenced the routing. It looks like maybe the update has dropped that info?
Although it looks like our prayers may be answered in an upcoming version! http://issues.umbraco.org/issue/U4-6946
That did not work unfortunately. I will roll back the DB and try the upgrade again.
Reverting the code (but not data) to 7.3.0 resolved the error, so it's indeed a bug introduced in 7.3.1.
I saw this too but was able to modify my code to resolve it. I'm not sure why it only just started becoming a problem, but I think you can fix this by either adding the 'overrides' keyword to the Index method. Or rename the Index method to be the same as the actual template name, assuming you are route hijacking here?
I had the same problem, and James´ solution worked for my project.
Before:
after:
regards René
Just encountered this problem today. I used James' other suggestion and renamed my Index method to match the name of my controller e.g.
Code now works again.
Hi David,
I'm not sure how your code worked before but it shouldn't have. I imagine there was a bug in the Umbraco pipeline in previous versions that somehow allowed this.
You are getting the error because you have two method calls with the same name in your controller
Index
. There is a virtual instance in your base controller plus your instance. The framework simply doesn't know which method is the correct one.James and René are both correct.
Your code should be as follows:
This tells the framework the override virtual Index method with your own version.
Veronica - Renaming the method work as the route handler will look for a method matching the document type name first and you have also removed the duplicate method signature from your code.
I hope that clears a few things up.
Cheers
James
@James, your solution works, but not with anything other than a RenderModel. What if I have an id or a custom model that i need binded on request.
I've added an issue for this problem as the given solution isn't suitable for all circumstances.
See http://issues.umbraco.org/issue/U4-7399
The bug is a result of a change to the
RenderActionInvoker
class. A short term solution is to register a customer controller factory which instantiates the previous version'sRenderActionInvoker
class.I'm not sure if anyone is still on this thread but I just ran into this issue when setting up my local site and upgrading from Umbraco 7.2.6 to 7.5.9.
The error message i get is:
The current request for action 'Index' on controller type 'HomePageController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index(Umbraco.Web.Models.RenderModel) on type DiamFusion.Web.Controllers.HomePageController System.Web.Mvc.ActionResult Index(Umbraco.Web.Models.RenderModel) on type Buzz.Hybrid.Controllers.SurfaceRenderMvcController
The code for the "HomePageController" is:
namespace DiamFusion.Web.Controllers { public class HomePageController : WebControllerBase { [DonutOutputCache(CacheProfile = "FiveMins")] public override ActionResult Index(RenderModel model) { return this.CurrentTemplate<>
I would greatly appreciate any help I can get.
Thanks, Derek
is working on a reply...