I use UrlHelper to create the URL, however I get an ArgumentNullException when I call the Action method (action, controller, route).
UrlHelper urlHelper = new UrlHelper(); if (!string.IsNullOrEmpty(notificacao.NotAction)) { NotRequestUrl = urlHelper.Action("myAction", "myController", HMTLHelperExtensions.convertStringToRouteValueDictionary(myparameters)); }
I created a helper function that creates object route values ββfor me (and it works correctly).
public static RouteValueDictionary convertStringToRouteValueDictionary(string parametros) { RouteValueDictionary dicionario = new RouteValueDictionary(); foreach (string parametro in parametros.Split(';')) if (parametro.Split('=').Count() == 2) dicionario.Add(parametro.Split('=')[0], parametro.Split('=')[1]); return dicionario; }
The strangest thing is that it already works inside the controller, but it does not work in a separate class (for example, in BusinessLayer / Facade).
None of the arguments matter.
It is called from the Task method.
I also tried to get a context like:
UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
But it HttpContext.Current returns null to me.
source share