I have this on Razor page
Index.cshtml
@for (int i = 0; i < Model.Count(); i++)
{
var cars = Model.ElementAt(i);
<a href="@Url.Action("Cars","Home", new { id = cars.Id })">
}
And I want to replace this in javascript using Jquery Ajax.
$.ajax({
type: "Get",
url: '/Cars/Home',
data: {
id: $(this).attr("id")
},
dataType: "json",
success: function (data) {
for (var i = 0; i < data.length; i++) {
html1.push("<a href='Cars/Home', new { id = cars.Id })>");
html1.push("</a>");
}
$("#wraps").html(html1.join(""));
}
})
This give me an error. However, how can I do this thing?
new { id = cars.Id }, that's C# syntax. Assign the ID just like you would if you wrote the HTML by hand.