ASP MVC ActionLink 导致 URL 无效
在我看来,使用标准路由模式
{controller}/{action}/{code}
,然后使用标准 ActionLink
<%: ActionLink("Details", "Details", new { code = item.Code }) %>
当用户输入“N/A”作为其代码时,我会看到以下 URL
http://localhost/AbsenceCode/Details/N/A
当我希望看到此内容时
http://locahost/AbsenceCode/Details/N%2FA
另外,如果用户将“A:B”作为其 代码代码我看到正确的 URL(冒号是 url 转义的),但我从服务器收到“400 错误请求”。
有人有解决这些问题的办法吗?我无法强迫客户仅使用 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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
我想出了一个解决方案,源代码可以在这里找到:
https://mrpmorris.blogspot.com/2012/ 08/asp-mvc-encoding-route-values.html
I've come up with a solution, source code is available here:
https://mrpmorris.blogspot.com/2012/08/asp-mvc-encoding-route-values.html