一直在爲此掙扎了一整天,我如何將actionlink id傳遞給jQuery ajax調用來啓用部分頁面更新。獲取點擊的ActionLink id並將其作爲函數參數傳遞
<li>@Html.ActionLink(@item.strCountry, "Index", "Weather", new { id = Regex.Replace(@item.strCountry, " ", "-") }, new { @class = "getCities" })</li>
jQuery的
<script>
$(function() {
$(".getCities").click(function() {
$.ajax({
//url: this.href,
url: '@Url.Action("pvDisplayListOfWeatherCities", "Weather")',
type: 'GET',
data: { id: $('#id').val() },
dataType: 'Json',
success: function (result) {
alert(result.test);
},
error: function() {
alert("error");
}
});
return false;
});
});
</script>
感謝
喬治
作爲附加說明:'dataType'屬性區分大小寫。它應該是'「json」'而不是'「Json」'。 – LeGEC