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
2009-09-27 19:49:53
would you happen to have an example?
2009-09-27 20:04:53
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
2009-09-27 20:28:16
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.
2009-09-27 20:31:49
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
2009-09-27 21:42:07