我有一个链接,可以将一些数据提交到控制器。它能有效地更新数据。但是我想改变父级div的CSS,但它并没有发生什么变化。我尝试了很多变化,但我一定是做错了什么。
以下是代码:
视图:
@foreach (var item in Model)
{
<div class="added-property-excerpt">
...
<div class="added-property-links">
...
@if (!item.IsPropertyDisabled) {
@Html.ActionLink("Take off the Market" , "Disable", "Property", new { id = item.PropertyId }, new { id ="disable-link" })
}
else {
@Html.ActionLink("Bring on the Market" , "Enable", "Property", new { id = item.PropertyId }, new { id ="enable-link" })
}
</div>
</div>
}
JQuery
<script>
$(function () {
$('a#disable-link').click(function (e) {
$('.added-property-links').text('loading...');
$.ajax({
url: this.href,
dataType: "text json",
type: "POST",
data: {},
success: function (data, textStatus) { }
});
$(this).closest('.added-property-excerpt').css("background", "red");
// $(this).parent('.added-property-excerpt').css("background", "red");
e.preventDefault();
});
});
</script>