tags:

views:

55

answers:

2

I am trying to make a url string to one of my mapped routes in the CS file. I can do it in the aspx file via the html helpers. How do you make a url in the CS file?

+1  A: 

Create an instance of System.Web.Mvc.HtmlHelper in your C# method, and use that to call your Html Helper methods.

Robert Harvey
would you happen to have an example?
Not without more information about what you're trying to do. If you just want to build an Url in a controller method, korchev's suggestion of using the UrlHelper class would be easier, as it doesn't require a ViewContext and ViewContainer as arguments to the constructor.
Robert Harvey
I can use the urlhelper but how do you get the requestcontext value? I am not using this method in a controller. It is in my model.
I know how to get it in the controller, but not in the model. In the controller, it is ControllerContext.RequestContext. Which makes sense, because a RequestContext doesn't actually exist until a request has occurred.
Robert Harvey
+2  A: 

You can use the UrlHelper class.

korchev