我在 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变量注入(inject)到html助手Url.RouteUrl中吗?
提前致谢
问候。
何塞。
最佳答案
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);
});
关于jquery - ajax回调中的Url.RouteUrl并使用jquery添加参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12161677/