3

I have a razor view which has a hidden field Model.Token. The Token consist of special characters. This Token is appended to a link in href.

<a href='http://localhost.com?token=@Model.Token'>Link</a>

If Model.Token has a +, the link renders it as a blank space. That is, if

Model.Token = 'ABC+DE'

The link becomes

http://localhost.com?token=ABC DE

How do I encode the Token in the link so that + is not removed? Do I need to use have a js and use encodeURI, or is there a better way to achieve this?

Jaseem Abbas
  • 5,028
  • 6
  • 48
  • 73

1 Answers1

1

You can try the System.Uri

<a href='http://localhost.com?token=@Uri.EscapeUriString(Model.Token)'>Link</a>
Huy Hoang Pham
  • 4,107
  • 1
  • 16
  • 28