i get this error when i click the button:
deletethisproduct is not defined at HTMLAnchorElement.onclick
i know it's not the best idea to use onclick but i'm using it because i want to get the product id from the model for this instance and pass it to the function
this is my link:
<a href="#" class="btn btn-danger" onclick="deletethisproduct(@item.product_id)">Delete </a>
and this is the js function:
@section scripts{
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
var deletethisproduct = function (productid) {
$.ajax({
method: 'POST',
url: "/Cart/deletecart",
data: { "id": productid },
success: function (data) {
console.log(data);
// $("#mymodalBodyDiv").html(data);
},
error: function (msg) {
alert("something wrong" + msg);
}
});
}
</script>
}
so why it's not defined ? and is there any other idea that can i get the product-id for this instance and pass it to the function without the onclick() ?
Edit: i think jquery is not read or something like that i don't know why although i am using it in another view with the same links!
<button class="btn btn-dange mythis">this </button>
i tried simply to alert from this button but nothing has happen no alert and no errors appeared in the console it also didn't say that "$" is not defined !
$('.mythis').click(function () {
alert("hiiii")
}