0

How can I pass an URL to another website as parameter to an action method? For example: https://www.youtube.com/watch?v=IEgkUKCwi30

Something like this won’t work:

http://localhost:61596/MyController/MyAction?Url=https://www.youtube.com/watch?v=IEgkUKCwi30

Do I need to kind of encode the URL?

2
  • From where you want to send the parameter? View ??? how? Button/Links ? Commented Apr 27, 2015 at 10:27
  • Parameter is part of a menu item (used to build the application menu), stored in the database. The menu gets rendered in partial view using some custom HTML helpers. Commented Apr 27, 2015 at 10:50

1 Answer 1

1

You need to encode it, yes. There is a special utility for this, HttpServerUtility.UrlEncode:

string urlParam = Server.UrlEncode("https://www.youtube.com/watch?v=IEgkUKCwi30");

If in the view, you can also use UrlHelper.Encode:

Url.Encode("https://www.youtube.com/watch?v=IEgkUKCwi30")
Sign up to request clarification or add additional context in comments.

Comments

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.