Asp.Net MVC using Tilde in href attribute for relative paths

Viewed 2368

Using MVC5 and razor.

Case #1:

var url='~/path';
<a href='@url'>test</a>

WRONG I get: http://www.example.com/~/path

Case #2

var url='/path';
<a href='~/@url'>test</a>

RIGHT I get: http://www.example.com/path

Is there a way to have razor correctly interpret the tilde? in other words, if I absolutely want to include the tilde in a string as in case #1, is there a way to get it to work?

1 Answers
Related