- ASP.NET MVC 5
- T4MVC (https://github.com/T4MVC/T4MVC)
- ABP (http://aspnetboilerplate.com/)
I know it is possible to use T4MVC to generate a URL based on a specific action using UrlHelper(). See SO and here. However I ultimately need to do this during Application_Start() due to ABP requirements.
So in essence within Application_Start() I have:
//Areas
AreaRegistration.RegisterAllAreas();
//Routes
RouteConfig.RegisterRoutes(RouteTable.Routes);
//Get the URL
var urlHelper = new UrlHelper();
var url = urlHelper.ActionAbsolute(MVC.Home.Index())
however this blows up with the following exception:
'UrlHelper.ActionAbsolute(MVC.Home.Index())' threw an exception of type 'System.NullReferenceException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147467261
HelpLink: null
InnerException: null
Message: "Object reference not set to an instance of an object."
Source: "T4MVCExtensions"
StackTrace: " at System.Web.Mvc.T4Extensions.ActionAbsolute(UrlHelper urlHelper, ActionResult result)"
TargetSite: {System.String ActionAbsolute(System.Web.Mvc.UrlHelper, System.Web.Mvc.ActionResult)}
however if I inspect the contents of things (at runtime) they appear to all be populated:
MVC.Home.Index()
{T4MVC_System_Web_Mvc_ActionResult}
Action: "Index"
Controller: "Home"
Protocol: null
RouteValueDictionary: {System.Web.Routing.RouteValueDictionary}
MVC.Home.Index().GetRouteValueDictionary()
{System.Web.Routing.RouteValueDictionary}
Count: 3
Keys: Count = 3
Values: Count = 3
Results View: Expanding the Results View will enumerate the IEnumerable
So can anyone shed any light on why this is blowing up? Or put another way how do I get the absolute url for an action using T4MVC inside Application_Start()?