我在帐户代码中的符号方面遇到问题,我正在尝试使用如下所示a href
创建URL。在我看来,我正在尝试使用 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>")
当我有一个像APPLA&D
这样的帐户代码时,就会出现问题:id作为APPLA
传递(缺少&D
)。
如何解决这个问题?我假设你不能在a href
中做到这一点,因为&
不能是 URL 中的值?
对 URL 参数进行编码。未经测试(因为我现在没有可用的 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>")
这假定ClientTemplate
正在替换匿名对象的id
和group
属性。