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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With