I was trying to execute RedirectToAction(actionResult)
from my base controller but IntelliSense didn't show this overload. I have found out RedirectToAction is placed into every T4MVC controller partial class. I kind of understand why it was implemented this way... but wouldn't it be better to have an alternative implementation which would be an extension method to Controller? Or is there a better solution for my case?

- 24,674
- 56
- 152
- 266
4 Answers
If you
kind of understand why it was implemented this way...
then you could implement it the same way in your base controller and you're good to go
private ActionResult RedirectToAction(ActionResult actionResult)
{
var callInfo = actionResult.GetT4MVCResult();
return RedirectToRoute(callInfo.RouteValueDictionary);
}

- 5,901
- 8
- 45
- 86
-
Yep. I even could implement extension method which I am talking about in the question. But I am interested why it is implemented this way: it is a bit strange to implement controller inspecific logic into every controller. – SiberianGuy Jun 11 '12 at 06:58
-
If you're really interested, it's much better to ask David Ebbo directly on T4MVC discussion list - http://t4mvc.codeplex.com/discussions I don't think anyone else would give you exact answer why he did it that way, and not the other :) We could only discuss pros/cons. – Shaddix Jun 11 '12 at 09:15
The difficulty is that the implementation of RedirectToAction needs to call Controller.RedirectToRoute, which is protected and not public. Hence you would not be able to call it from an extension method.
Another downside is that even if it worked, you'd then have to call this.RedirectToAction(...)
instead of just RedirectToAction(...)
.

- 42,443
- 8
- 103
- 117
If you just want IntelliSense to work, you could create your own extension method. It'll resolve with lower priority than the class member method that's provided by the T4MVC controller partial class, so it should participate in IntelliSense, but not actually get touched by the compiler.
If you're asking at a higher philosophical level "why'd they do that?", then I'm afraid I'll have to defer to the real professionals.

- 26,911
- 4
- 71
- 95