在 Telerik href URL 中包含带有 & 符号的参数值



我在帐户代码中的符号方面遇到问题,我正在尝试使用如下所示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正在替换匿名对象的idgroup属性。