---
title: "How to call UrlHelper in Asp.net MVC?"  
description: "How to call UrlHelper in Asp.net MVC?"  
author: "Anonymous User"  
published: 2014-11-21  
updated: 2014-11-22  
canonical: https://www.mindstick.com/forum/12673/how-to-call-urlhelper-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["model", "url routing"]  
reading_time: 1 minute  

---

# How to call UrlHelper in Asp.net MVC?

I need to generate some URLs in a [model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model) in [ASP.NET MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc). I'd like to call something like UrlHelper.Action() which uses the routes to generate the URL. I don't mind [filling](https://yourviews.mindstick.com/audio/1303/the-power-of-silence-what-happens-when-you-stop-filling-every-moment) the usual blanks, like the hostname, scheme and so on.

Is there any [method](https://www.mindstick.com/forum/166/webservice-method) I can call for that? Is there a way to construct an UrlHelper?

## Replies

### Reply by Anonymous User

I like Omar's answer but that's not working for me. Just for the record this is the solution I'm using now:

```
var httpContext = HttpContext.Current;if (httpContext == null) {  var request = new HttpRequest("/",
"http://example.com", "");  var response = new HttpResponse(new
StringWriter());  httpContext = new HttpContext(request,
response);}var httpContextBase = new HttpContextWrapper(httpContext);var routeData = new RouteData();var requestContext = new RequestContext(httpContextBase,
routeData);return new UrlHelper(requestContext);
```


---

Original Source: https://www.mindstick.com/forum/12673/how-to-call-urlhelper-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
