如果我有一个像这样生成的 url
<%=Html.ActionLink("Link name", "MyAction", "MyController", new { SomeParameter = "value with spaces" })%>
是否可以像这样轻松生成输出html
<a href="/MyController/MyAction/value+with+spaces">
代替
<a href="/MyController/MyAction/value%20with%20spaces">
或者我是否最好考虑重载 ActionLink 方法并在返回字符串时替换那些字符?
最佳答案
Or am I best looking at overloading the ActionLink method and replacing those characters when returning the string?
是的。
更简单的方法是制作一个空格破折号替换器扩展方法。或者只是手动调用 Replace。
<%=Html.ActionLink("Link name", "MyAction", "MyController", new { SomeParameter = "value with spaces".Replace(" ", "-" })%>
关于asp.net-mvc - ASP.NET MVC HtmlHelper.ActionLink 将 %20 替换为 +,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2152417/