Reputation: 9277
I have the following code in the callback of an ajax call:
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}));");
});
I would like to use this.Name and this.UrlTitle inside of the foreach.
The problem is that i want to avoid to use querystrings variables (?param=1, etc...)
Do you know how to inject jquery variables into the html helper Url.RouteUrl?
Thanks in advance
regards.
Jose.
Upvotes: 1
Views: 1723
Reputation: 1038850
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);
});
Upvotes: 4