How to properly map an Area route with T4MVC...

Nov 12, 2013 at 4:21 PM
I'm using T4MVC with ASP.NET MVC 5. Given the following route in my AreaRegistration:
context.MapRoute(
                name: "MyArea_myRoute",
                url: "MyArea/{id}",
                defaults: new { area = "MyArea", controller = "MyController", action = "MyAction" }
            );
I'd like to use T4MVC for specifying the default values like so:
context.MapRoute(
                name: "MyArea_myRoute",
                url: "MyArea/{id}",
                defaults: MVC.MyArea.MyController.MyAction()
            );
However, this causes an InvalidOperationException ("The matched route does not include a 'controller' route value, which is required."). If I specify the area as a route value, it works (yes, I'm using an async controller):
context.MapRoute(
                name: "MyArea_myRoute",
                url: "MyArea/{id}",
                defaults: MVC.MyArea.MyController.MyAction().Result.AddRouteValue("area", "MyArea")
            );
If I'm referencing the area in the class generated by T4MVC, why must I also add the route value?
Coordinator
Nov 12, 2013 at 7:56 PM
I've never tried using it this way. The special ActionResults returned by T4MVC are meant to be consumed by T4MVC specific APIs, and not consumed directly as objects that have properties.

Try maybe using defaults: MVC.MyArea.MyController.MyAction().GetRouteValueDictionary()