1

我在 ajax 调用的回调中有以下代码:

jQuery.each(res, function () 
{
   var anchor = $("<a/>", { id: this.UrlTitle, text: this.Name.toLowerCase(), style: 'color:#000000;' });
    anchor.attr('href', @(Url.RouteUrl("Detail",new{indicator=this.Name,urltitle=this.NameUrl}));");
});

我想在 foreach 中使用 this.Name 和 this.UrlTitle。

问题是我想避免使用查询字符串变量(?param = 1等......)

你知道如何将 jquery 变量注入到 html helper Url.RouteUrl 中吗?

提前致谢

问候。

何塞。

4

1 回答 1

4
jQuery.each(res, function () {
    var anchor = $('<a/>', { 
        id: this.UrlTitle, 
        text: this.Name.toLowerCase(), 
        style: 'color:#000000;' 
    });
    var url = '@Url.RouteUrl("Detail", new { indicator = "__indicator__", urltitle = "__title__" })'
        .replace('__indicator__', encodeURIComponent(this.Name))
        .replace('__title__', encodeURIComponent(this.NameUrl));
    anchor.attr('href', url);
});
于 2012-08-28T14:38:30.223 回答