Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net-mvc

If I have a url generated like this

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

is it possible 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?

like image 844
mjallday Avatar asked Mar 09 '26 02:03

mjallday


1 Answers

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(" ", "-" })%>
like image 77
John Farrell Avatar answered Mar 10 '26 15:03

John Farrell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!