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?

2 Answers 2

2

You can use the UrlHelper class.

Sign up to request clarification or add additional context in comments.

Comments

1

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

4 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.