Asp.net-mvc – In ASP.NET MVC how can I use the Razor @Url.Content() helper from C# code

asp.netasp.net-mvc

I'm trying to write a html helper extension that outputs an image tag.
I need to access (within C# code) something like Razor's @Url.Content() helper to get the proper URL for the current context.
How does one do this?

Best Solution

Use the following to mimic Url.Content in code.

VirtualPathUtility.ToAbsolute("~/url/");