简体   繁体   English

在Telerik href URL中包括参数值和符号

[英]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正在替换匿名对象的idgroup属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM