我试图在服务器上处理时绕过Html.ActionLink所做的路由值编码。例如,我有跟随ActionLink
@Html.ActionLink("Edit", "_SoftwareRequestEdit", "SoftwareRequest", new {id = "#= Id #"}, null)
它会生成一个像这样的链接
<a href="/Admin/SoftwareRequest/_SoftwareRequestEdit/%23%3d%20Id%20%23">Edit</a>
但我不想将其发送到浏览器
<a href="/Admin/SoftwareRequest/_SoftwareRequestEdit/#= Id #">Edit</a>
&#34;#= Id#&#34; 路由值必须按原样发送到浏览器,因为它由前端框架Kendo UI Web处理,用相应的整数值替换表达式&#34;#= Id#&#34; 。
答案 0 :(得分:1)
这非常混乱......但是,如果你需要这样做,你总是可以手动构建标签。
<a href="@(Url.Action("Edit", "_SoftwareRequestEdit", "SoftwareRequest"))/#= ID #">Edit</a>
请注意,我还没有测试过这段代码......
编辑: 它实际上可以为您提供所需的内容,因为大多数浏览器都会对#34; a&#34;中的所有内容进行网址编码。标签,因为空格不是有效的网址字符:http://www.w3schools.com/tags/ref_urlencode.asp
答案 1 :(得分:0)
Html.ActionLine具有片段参数
的重载public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)
协议和主机名只能传递空字符串