开发者

ASP MVC ActionLink causes invalid URL

开发者 https://www.devze.com 2023-01-24 12:42 出处:网络
Using the standard route pattern {controller}/{action}/{code} and then a standard ActionLink in my view

Using the standard route pattern

{controller}/{action}/{code}

and then a standard ActionLink in my view

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

When the user has entered "N/A" as their code I see the开发者_如何学C following URL

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

When I expect to see this

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

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

Does anyone have solutions to these problems? I cannot force the customer to use URL safe characters only.


Try

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


I've come up with a solution, source code is available here: https://mrpmorris.blogspot.com/2012/08/asp-mvc-encoding-route-values.html

0

精彩评论

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