ASP MVC ActionLink Causes Invalid URL

Using the standard route pattern

{controller}/{action}/{code}

and then standard actionlink in my view

<%: ActionLink("Details", "Details", new { code = item.Code }) %>

When the user entered "N / A" as their code, I see the following URL

http://localhost/AbsenceCode/Details/N/A

When I expect to see it

http://locahost/AbsenceCode/Details/N%2FA

Also, if the user has “A: B” as the code, I see the correct URL (the colon is hidden using the url), but I get a “400 bad request” from the server.

Does anyone have solutions to these problems? I cannot force the client to use only secure URLs.

+3
source share
2 answers

Try

<%: Html.ActionLink("Details", "Details", new { code = Url.Encode(item.Code) }) &>
0

Source: https://habr.com/ru/post/1774476/


All Articles