Reputation: 155
I have one text that have '%' and I would like to use in link, but I receice a error,(bad request)
Sample:
@{
var title = "less than 1% ."; ///this I would like to pass in url
var url = HttpUtility.HtmlEncode(title); //I try it, but not work!
}
<a href="/cidades/cidade/Categoria/@url">go to city</a>
I use this route:
routes.MapRoute(
name: "Categoria",
url: "{controller}/{action}/categoria/{nome}",
defaults: new { controller = "Cidades", action = "Index", id = UrlParameter.Optional }
);
Upvotes: 0
Views: 69
Reputation: 152521
HtmlEncode
is for translating special charaters to HTML. Use UrlEncode
to encode special characters into a valid URL:
var url = HttpUtility.UrlEncode(title);
Upvotes: 1