我有一个'%'的文字,我想在链接中使用,但我收到错误,(错误的请求)
样品:
@{
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>
我使用这条路线:
routes.MapRoute(
name: "Categoria",
url: "{controller}/{action}/categoria/{nome}",
defaults: new { controller = "Cidades", action = "Index", id = UrlParameter.Optional }
);
答案 0 :(得分:1)
HtmlEncode
用于将特殊字符转换为 HTML 。使用UrlEncode
将特殊字符编码为有效的网址:
var url = HttpUtility.UrlEncode(title);