[英]Including parameter value with ampersand in Telerik href URL
I have a issue with symbols in account code which I am trying to create the URL using a href
as below. 我在帐户代码中遇到符号问题,我尝试使用
a href
如下创建URL。 In my view I am trying to pass an id to my controller using Telerik grid. 在我看来,我正在尝试使用Telerik网格将ID传递给我的控制器。
.Template(x => Html.ActionLink("Month Ends", "MonthEndDates", new { id = x.Account, group = x.Group }))
.ClientTemplate("<a href=\"MonthEndDates?id=<#= Account #>&group=<#= Group #>\">" + "Month Ends" + "</a>")
The problem arises when I have a account code like APPLA&D
: the id is passed as APPLA
(missing the &D
). 当我有一个类似于
APPLA&D
的帐户代码时,就会出现问题:id作为APPLA
传递(缺少&D
)。
How would one go about solving this issue? 如何解决这个问题? I assume you cannot do this in
a href
as &
cannot be a value in a URL? 我假设您不能在
a href
执行此操作,因为&
不能在URL中是值?
Encode the URL parameters. 编码URL参数。 Untested (since I don't have Telerik available these days):
未经测试(因为这些天我没有Telerik可用):
.Template(x => Html.ActionLink("Month Ends", "MonthEndDates", new {
id = Net.WebUtility.UrlEncode(x.Account),
group = x.Group
}))
.ClientTemplate("<a href=\"MonthEndDates?id=<#= id #>&group=<#= group #>\">" + "Month Ends" + "</a>")
This assumes ClientTemplate
is substituting in the id
and group
properties from the anonymous object. 假定
ClientTemplate
正在替换匿名对象的id
和group
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.