In my MVC2 application I have an AccountController class inherited from Controller. I want to achieve the following: when a user tries to open Account/Payments/NewPayment AccountController.ExecuteNewPayment() method should be invoked.
I added the following route:
routes.MapRoute(
@"CreateNewRuntime",
@"{langId}/Account/Payments/NewPayment/{whatever}",
new { langId = @"default", controller = @"Account", action = @"ExecuteNewPayment"});
but when I try to request the path above I get HTTP 404 error message with “Requested URL” /Account/Payments/NewPayment and when I do that under debugger there’s an exception
A first chance exception of type ‘System.Web.HttpException’ occurred in System.Web.Mvc.dll
Additional information: The controller for path ‘/Account/Payments/NewPayment’ was not found or does not implement IController.
What am I doing wrong? How do I perform the mapping?
You need to include the
langidas part of your route or MVC will not map your URI to it even if you have a default specified.Take these two routes:
If I specify the URI of
/Account/Payments/NewPayment, which one of the routes should it pick? If MVC did use the default forlangIdthen the first route would always get used since it was declared before the other one. If you swapped the two then the second one would always get invoked.When you have varying data in the beginning of your URI’s you need to specify them and you cannot use the default value when specifying the route. In order for these two routes to be hit you would need a URI of
/eng/Account/Payments/NewPaymentand/eng/e/Account/Payments/NewPayment