$.ajax({
url: "/Home/GetAllSearchData",
datatype: "json",
type: "get",
data: {
text: Search,
city: city,
locality: locality
},
success: function(data) {
if (data.result != null) {
$("#table").find("tr:not(:first)").remove();
var tr;
for (var i = 0; i < data.result.length; i++) {
var res = [];
res = data.result[i].Id.split(",");
tr = $('<tr/>');
tr.append("<td>" + " <div class='dashboardmodal - body'><p><a href='@Url.Action("
SearchAction ", "
Home ", new { city = city })'>" + data.result[i].name + "</a></p>" + "</div></td>");
$('#table').append(tr);
}
var modal = document.getElementById('myModal');
modal.style.display = "block";
}
},
error: function(err) {
alert(err);
}
});
我正在尝试将城市变量值传递给锚标记参数,但收到错误the name does not exist in the current context
答案 0 :(得分:0)
最好将对象名称city更改为cityObj,然后尝试传递相同的内容。 或者只是尝试下面的一个并检查控制台
'@Url.Action("SearchAction", "Home")?city=' + city +
或者您可以尝试下面的内容,
'@Url.Action("SearchAction", "Home")', { city: city }
希望它有所帮助!!