开发者

ASP MVC ActionLink causes invalid URL

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜