0

In my ASP.NET MVC 5 app I have an area defined called Manage.

I am currently using the default route for this area:

context.MapRoute(
                "Manage_default",
                "Manage/{controller}/{action}/{id}",
                new { controller="Home", action = "Index", id = UrlParameter.Optional }
            );

The problem I have is when using additional parameters to an action, they are not bound. For example the MonthlyStats action of the Sites controller is defined as public ActionResult MonthlyStats(int id, DateTime? month) but when hitting /Manage/Sites/MonthlyStats/138/?month=2015-02-01, month is always null.

/Sites/MonthlyStats/ was only recently moved the the Manage area and it worked perfectly before this.

Looking in RouteDebugger, month is never present in the RouteData collection as I expect is should be (could be wrong here).

enter image description here

Ant Swift
  • 20,089
  • 10
  • 38
  • 55
  • This is sometimes helpful, it takes a bit to understand the output from the debugger but can be a great tool for troubleshooting routing issues: http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx/ – AaronLS Mar 24 '15 at 23:56
  • Also you should show your controller declaration, any attributes on the controller or action method, and the folder structure the controller is under, just to rule out potential errors there or typos. – AaronLS Mar 24 '15 at 23:57
  • Also any other MapRoute calls you have in the order they are called, as sometimes your area route might be ignored because another route that has a "broader" definition will catch the URL first. – AaronLS Mar 24 '15 at 23:58
  • Hi @AaronLS, I've added the output from Route Debugger to the post. There are no other mappings defined in the application or any Route related attributes on the controller or Action. The controller is defined under /Areas/Manage/Controllers/SitesController. – Ant Swift Mar 25 '15 at 00:01

1 Answers1

0

Make sure:

  • you have a SiteController in the PTree.Reslink.WebUI.Area.Manage namespace(make sure casing matches).
  • it is SiteController and not SitesController since it appears your route was parsed with a singular name of just "Site". Are you sure you're typing the URL consistently?
  • both the class and action are public.
  • That they are in the Areas/Manage/Controllers folder.
  • Seems like datetime is troublesome, might be culture specific format, try mm/dd/yyyy as well as couple of these variations. The fact that couple answers claim different ordering of the year/day indicates it might be culture specific: stackoverflow.com/questions/6177626/

It seems a bit odd that the route didn't parse out the Manage area into the route data though. Are you going directly to a URL or clicking through an ActionLink? Verify if you're using an action link that you are including the area in the route data collection. Best to go directly to the URL first to verify it is working, then troubleshoot any ActionLink.

AaronLS
  • 37,329
  • 20
  • 143
  • 202
  • SitesController is in the namespage PTree.Reslink.WebUI.Areas.Manage.Controllers. As above, the controller is defined as the plural. All are public, the view actually appears correctly just without the month filter applied. The folder is correct. – Ant Swift Mar 25 '15 at 00:11
  • I am going directly to the url and have the same issue. – Ant Swift Mar 25 '15 at 00:14
  • @AntSwift I don't know if it makes a difference but you could try "2011-10-17T12:35:00" as the datetime parameter just to see if the model binder requires the time portion. – AaronLS Mar 25 '15 at 00:20
  • The result is the same as before unfortunately. – Ant Swift Mar 25 '15 at 00:21
  • @AntSwift Seems like datetime is troublesome, might be culture specific format, try mm/dd/yyyy as well as couple of these variations. The fact that couple answers claim different ordering of the year/day indicates it might be culture specific: http://stackoverflow.com/questions/6177626/asp-net-mvc-default-model-binder-problem – AaronLS Mar 25 '15 at 00:28
  • Bingo, that's got it. This has worked previously which is very confusing. – Ant Swift Mar 25 '15 at 00:34