2014-02-05 30 views
0

我有以下行生成的URL通过Html.RouteLink有特殊字符

  @Html.RouteLink(type.Description, "ListingsWithTypeSpecified", new { country = Model.CountryCode, state = Model.State, city = Model.CurrentCity.Name.ToLower(), description = type.Description.ToLower(), id = type.TypeID }) 

产生

http://some.com:9609/ca/on/london/physiotherapy%20%20%26%20acupuncture/2 

http://some.com:9609/ca/on/london/health%20department/19

第一个具有空间和一个&,第二个刚刚有空间 为第一个,我想仍然显示

http://localhost:9609/ca/on/london/physiotherapy and acupuncture/2 

这一个我明白了“和”将工作更换&,但是我还是不想%20个空格代替我想有一个干净的URL。 我应该使用哪种方法来正确显示由Html.RouteLink创建的友好网址?

回答

0

用 - (如:

type.Description.ToLower().Replace(" ", "-") 
+0

可以通过调用一些内置的功能来完成,我试图避免手动替换字符,而是使用内置的处理它approperiately – Zoinky

+0

你可以添加自己的扩展方法,像这个: '公共静态字符串ReplaceSpace(字符串描述) { return description.Replace(“”,“ - ”); }' 然后根据需要添加替换规则 – Andrew