I've got a route that looks like this:
routes.MapRoute(
"BlogTags",
"Blog/Tags/{tag}",
new { controller = "Blog", action = "BrowseTag", viewRss = false }
);
And I create a URL using that route like this:
<%= Html.RouteLink(Html.Encode(sortedTags[i].Tag),
new { action = "BrowseTag", tag = sortedTags[i].Tag })%>
However, when a tag with a # character (like "C#") is used, the routing engine doesn't escape it, so I get a URL that looks like this:
<a href="/Blog/Tags/C#">C#</a>
What I need is the # escaped so that it looks like this:
<a href="/Blog/Tags/C%23">C#</a>
I tried doing a Url.Encode on the tag before it went into the route, like this:
<%= Html.RouteLink(Html.Encode(sortedTags[i].Tag),
new { action = "BrowseTag", tag = Url.Encode(sortedTags[i].Tag) })%>
But that makes the routing engine double escape the # (which causes an ASP.NET crash with a bad request error)):
<a href="/Blog/Tags/C%2523">C#</a>
How can I get the routing engine to escape that # character for me correctly?
Thank you for your help in advance.