I want to generate a url from a tag name.
In my view (asp.net mvc) I have the following:
<%= Html.ActionLink(Html.Encode(tagName),
"tagged" //action,
"posts" //controller,
new {tagName=Html.UrlEncode(tagName)} //querystring argument,
new {@class="tag"} //html attributes)
%>
But this generates the following URL if the tagName is "c#" (without the quotes):
http://localhost/posts/tagged/c%2523
which results in Http 400 error - Bad Request
On Stackoverflow, the url for the same "c#" tag generates "c%23" instead of "c%2523"
I tried Html.UrlEncode, Uri.EscapeDataString, Uri.EscapeUrlString, but none of those produces the desirable "c%23" format.
So how should I encode the tagName for the anchor?