Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ActionResult to a URL string in a static method

Tags:

asp.net-mvc

When I have access to UrlHelper I can convert an ActionResult to a string (i.e. the actual URL) like this: urlHelper.RouteUrl(actionResult.GetRouteValueDictionary());

How can I do that same from a static method where I don't have access to UrlHelper? Thanks.

like image 804
pbz Avatar asked Nov 04 '25 19:11

pbz


1 Answers

Just add a using statement for System.Web.Mvc, and create an instance of the UrlHelper class in your static method.

like image 172
Robert Harvey Avatar answered Nov 06 '25 22:11

Robert Harvey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!