I have an id element "Remove" (in a partial view) clicking on which shall remove the producerId from a movie. When I click on it, the jquery function is not responding and nothing happens. Please help me to see what is going wrong here.
Here is my view html (_ProducerIndex.cshtml) -
@model MovieInfo.Models.Producer
@if (Model != null)
{
<table>
<tr>
<td>
@Html.DisplayFor(model => model.Name)
</td>
<td>
<div id="removeproducer" data-mi-producerId="@Model.ProducerId" data-mi-movieid="@ViewData["Movie"]">
<a href="#">Remove</a>
</div>
</td>
</tr>
</table>
}
And here is what my jquery is doing -
$(function () {
var removeProducer = function () {
var $a = $(this);
var prodId = $a.attr("data-mi-producerid");
var mov = $a.attr("data-mi-movieId");
var options = {
url: "/Movie/ProducerRemove",
contentType: "application/json",
data: JSON.stringify({ producerId: prodId, movie: mov }),
type: "post",
dataType: "html"
};
$.ajax(options).done(function (data) {
var $target = $("#producerindex");
$target.html(data);
});
return false;
};
$("#removeproducer").on("click", removeProducer);
});
I tried putting alert statement in removeProducer function but it is not getting called.