开发者

ASP.NET MVC HtmlHelper.ActionLink replace %20 with +

开发者 https://www.devze.com 2022-12-18 03:42 出处:网络
If I have a url generated like this <%=Html.ActionLink(\"Link name\", \"MyAction\", \"MyController\", new { SomeParameter = \"value with spaces\" })%>

If I have a url generated like this

<%=Html.ActionLink("Link name", "MyAction", "MyController", new { SomeParameter = "value with spaces" })%>

is it poss开发者_如何学Pythonible to easily generate the output html like so

<a href="/MyController/MyAction/value+with+spaces">

instead of

<a href="/MyController/MyAction/value%20with%20spaces">

Or am I best looking at overloading the ActionLink method and replacing those characters when returning the string?


Or am I best looking at overloading the ActionLink method and replacing those characters when returning the string?

Yes.

The easier way is to just make a space-dash replacer extension method. Or just call Replace manually.

<%=Html.ActionLink("Link name", "MyAction", "MyController", new { SomeParameter = "value with spaces".Replace(" ", "-" })%>
0

精彩评论

暂无评论...
验证码 换一张
取 消