Cristhian Sandoval
Cristhian Sandoval

Reputation: 1

URL in Links converts & to & making the URL invalid

I use the label @ {var url = Html.Display ("URL"); } Click here But he turns me the & in & amp; and this invades the url.

How can I solve that?

@ {var url = Html.Display ("URL"); } Click here

Upvotes: 0

Views: 72

Answers (2)

Nijin P J
Nijin P J

Reputation: 1322

Use encodeURIComponent() which is the correct method to use

  encodeURIComponent("URL")

Upvotes: 0

Hooman Bahreini
Hooman Bahreini

Reputation: 15569

When you say, Html.Display("URL"), "URL" is a string and "URL" would be displayed. I assume what you want is Html.Display(URL) where URL is a variable containing your url.


Html.Display(myUrlVariable) encodes your string to protect you against XSS attack.

If you don't want myUrlVariable variable to be encoded, you can use HTML.Raw(myUrlVariable)

Upvotes: 1

Related Questions