ActionLink中的URL编码参数? [英] URL-encode parameters in ActionLink?
本文介绍了ActionLink中的URL编码参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注册了以下路线;
routes.MapRoute(
"LocationsByArea",
"Locations/{system}/{storage}/{area}",
new { controller = "StorageLocation", action = "Index" },
null
);
...以及我认为的以下代码;
...and the following code in my view;
<%= Html.ActionLink("Platser", "Index", "StorageLocation", new { system = Model.System, storage = Model.Storage, area = item.Name }, null)%>
我的问题是,当"area = item.Name"包含冒号时,例如区域4:1".如果单击渲染的链接,则会收到HTTP错误400,错误请求.我想我必须以某种方式对我的area参数进行编码,但是我不知道该怎么做.任何帮助都非常感谢.
My problem is when the "area = item.Name" contains a colon, e.g. "Area 4:1". If I click the rendered link I get HTTP-error 400, Bad reqest. I guess I have to encode my area parameter in some way, but I cant figure out how. Any help is apreciated.
谢谢!
推荐答案
内置的编码/解码不起作用,因此建议您像这样滚动自己的轨道:
The built-in encoding/decoding does not work, so I suggest you roll your own, like this:
namespace MyProject.Helpers
{
public static class JobNameHelper
{
public static string JobNameEncode(string jobname)
{
return jobname.Replace(":", "---colon---");
}
public static string JobNameDecode(string jobname)
{
return jobname.Replace("---colon---", ":");
}
}
}
这篇关于ActionLink中的URL编码参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文