0

I am trying to setup index page route. It works this way:

routes.MapRoute("", "", new {controller = "Home", action = "Index"})

but if I replace it with T4MVC:

routes.MapRoute("", "", MVC.Home.Index());

somehow it doesn't work (I get a "The resource can not be found" error). Seems like I did it millions of times and it worked. So what am I doing wrong?

Update.

I used Route Debugger and found out the difference between ASP.NET MVC route and T4MVC route is that T4MVC adds Area="" while ASP.NET MVC doesn't (it keeps only controller and action).

SiberianGuy
  • 24,674
  • 56
  • 152
  • 266

3 Answers3

1

Update (7/15/2014): as a workaround, I think you'll need to add a dummy area to your project, e.g.

  • Right click Project and choose Add / Area. Name it 'Dummy' (or whatever)
  • You can delete everything in there except for the DummyAreaRegistration.cs file

Original answer:

If you 'Go to definition' on your MapRoute call, can you check that it indeed goes to a T4MVC overload? Note that if you're in an Area, you'll need to call MapRouteArea instead.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
0

Please notice that MVC.Home.Index() returns ActionResult

if you want to get name of action and controller, you have to write:

MVC.Home.Index().GetT4MVCResult().Controller - name of the Controller MVC.Home.Index().GetT4MVCResult().Action - name of the Action

Edited:

routes.MapRoute("", "", new {controller = MVC.Home.Index().GetT4MVCResult().Controller, action = MVC.Home.Index().GetT4MVCResult().Action})
Sergey
  • 471
  • 3
  • 10
  • Why is it "not so good". What if I rename the controller or action? – SiberianGuy Jul 14 '14 at 05:39
  • I could not be able to find example of where we had problems with areas, but anywhere you can try this. (Probably it was mvc 3 or so, and in mvc 4 and 5 it's already fixed) – Sergey Jul 14 '14 at 11:39
0

The problem was caused with some problems with assemblybindings. I looked through Warnings in VS, pressed twice on the warning about assemblybindings and they were fixed. This question helped me a lot: T4MVC ArgumentOutOfRangeException in View

Community
  • 1
  • 1
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266