Basically, I want the same functionality as Url.Action, but outside of the controller. Is this possible?
While I'm sure I'll use it elsewhere, my current desire is to generate action url's inside of a viewmodel.
Basically, I want the same functionality as Url.Action, but outside of the controller. Is this possible?
While I'm sure I'll use it elsewhere, my current desire is to generate action url's inside of a viewmodel.
You can instantiate a UrlHelper
in your view model, like so:
UrlHelper helper = new UrlHelper(HttpContext.Current.Request.RequestContext);
Then, you can use this just like the one you use in your view:
string actionUrl = helper.Action("MyAction", "MyController");