Ambiguous Controller Names.aspx

suggest edit
Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



22 responses

  1. Avatar for Chris Hardy
    Chris Hardy January 11th, 2010

    Hey Phil,
    I came across this problem pretty quickly in the early beta. I think the Namespace fix isn't too bad at all.
    Good work!

  2. Avatar for Paco
    Paco January 11th, 2010

    Today I noticed the controllerfactory and mvchandler do not allow to call a controller just "Controller". I could not find any reason for that. The controllerfactory can cache the right controllertype with string.empty. I think it's a good convention for simplicity to call controllers ...Controller, but I think the mvc framework should not enforce programmers to use a convention which has no technical reasons. I would really like to see the conventions that are not used by mvc to be removed.

  3. Avatar for Craig
    Craig January 11th, 2010

    When I first heard of "areas", I assumed MVC would support URLs like Blogs/Home/Index and that I could create route definitions like {area}/{controller}/{action}/{id} and MVC would use the area part of the URL to distinguish controllers.
    Your fix removes the ambiguity for the compiler, but from the standpoint of creating URLs, do I have to name the Blogs Home controller different from the Forums Home controller? I can see a lot of naming inconvenience just to avoid ambiguity.

  4. Avatar for Simon W
    Simon W January 12th, 2010

    I also found this same problem and the namespace fix early on.
    What I think though is an outstanding issue (which I nearly reported) is if one namespace is a descendent namespace of the other you still get the error.
    For instance I had
    and would still receive an 'ambigious controller' error if those two namespaces contained the same controller.
    Of course I fixed this by making the namespaces completely unique.
    PS. I forget the *exact* details if I had Controllers.FunStuff or FunStuff.Controllers, and I wan't going to mention this anyway but since you did I thought it might be of use (especially if a change is made for RTM).

  5. Avatar for Thanigainathan
    Thanigainathan January 12th, 2010

    I agree with Craig .Why should the area name be a parameter in the url ?

  6. Avatar for Nick Kirkes
    Nick Kirkes January 12th, 2010

    On a related note, I've been having trouble getting an area to recognize a default controller. For example, if I have an Admin area defined and want the default controller for that area to be a DashboardController, specifying the controller in the base route doesn't send the url "~/Admin/" to the correct resource (it doesn't find any resource to display). If I try "~/Admin/Dashboard", then it works just fine. I have a post on StackOverflow and would really appreciate some input. Perhaps this is a bug?
    SO post:
    P.S. Sorry to hijack the comment thread, but at least there's some relationship to the main topic.

  7. Avatar for Becker
    Becker January 14th, 2010

    On a somewhat related note, where has the Microsoft.Web.Mvc.Build.dll assembly gone from the MVC2 RC release.
    It was present in the Preview 2 release (within VS2008 Tools installer) but is no longer present in RC. Is this no longer supported?

  8. Avatar for haacked
    haacked January 14th, 2010

    @Becker that's correct, it's been moved to the MVC Futures assembly.

  9. Avatar for Jarek
    Jarek January 18th, 2010

    Sorry, but I can't find it in futures zip file.

  10. Avatar for Jarek
    Jarek January 19th, 2010
  11. Avatar for Derek
    Derek January 24th, 2010

    Not to sound rude or anything - but this seems to me that it will be an excessively common problem.
    I would really advise these instructions being in the release notes - both for the release candidates, and the final - or some kind of tooling, comment, etc, in the final build output that elaborates it.

  12. Avatar for Tom John
    Tom John May 20th, 2010

    This works a treat (although have to agree that it should really be handled like controllers and actions in the routes).
    That asside - I've found that if the controller is in an alternate assembly, it seems that from within an area the controller cannot be resolved. Controllers works fine in alternate assemblies when there are no areas involved.
    Is there a solution to this situation?

  13. Avatar for Criação de Site
    Criação de Site August 4th, 2010

    thanks for the hint, i was looking a long time ago how solve this problem.

  14. Avatar for Daniel Steigerwald
    Daniel Steigerwald August 19th, 2010

    Thank you. It is exactly that fix I need. To bad I am not using ASP.NET MVC 2 RC, but ASP.NET MVC 3 PREVIEW.
    Anyway, blogging will safe Microsoft.

  15. Avatar for Long Le
    Long Le March 13th, 2011

    Don't use any MVC...You will get stuck. MVC can not handle any custom validation and hard to fix...For example...MVC do not has auto decimal and auto prevent letter or number input to EditorFor... It is nightmare to do MVC...

  16. Avatar for Prasanth S
    Prasanth S November 7th, 2011

    Great !! It is the answer I require

  17. Avatar for Erik
    Erik November 27th, 2012

    I'm tying to follow your post but get an strange error:
    The constraint entry 'Length' on the route with URL '{controller}/{action}/{id}' must have a string value or be of a type which implements IRouteConstraint.
    Do you know why? I only have the default routs in place!

  18. Avatar for Jorge Picco
    Jorge Picco May 18th, 2014

    There is at least one more problem that derives from having homonyms Controls. At a view when using a Helper method. For example:

    How to disambiguate which control you mean?

  19. Avatar for ozbob
    ozbob June 2nd, 2014

    @Html.ActionLink("AnchorContent","Portal","App", routeValues: new { area = "areaname" }, htmlAttributes:new { title = "actionlinktitle", alt = "link description"})

  20. Avatar for Arturo Torres Sánchez
    Arturo Torres Sánchez December 23rd, 2014

    Why isn't this generated by default in new projects? (or at least my MVC 3 project didn't have it)

  21. Avatar for Divyesh Kinariwala
    Divyesh Kinariwala May 17th, 2016

    your suggestion is good. but how you can render that view when you use Html.RenderAction("Index","Home") in your layout page. because i have issue with this and i also added namespace in both cs file i.e Routeconfig.cs and other one is my area

  22. Avatar for Bahtiyar Özdere
    Bahtiyar Özdere March 10th, 2017

    What can we do to priorotize namespaces instead of choosing one. Even when there are 2 controllers and actions with same name I am trying to choose one of them instead of conflict.