2 回答

TA貢獻1783條經驗 獲得超4個贊
你可以嘗試使用
foreach(var item in Model){
<form>
<input type="text" id="id" name="id" value="item.id"/>
<input type="button" class="btn" data-id="item.id" name="submit" value="Delete"/>
</form>
}
<script>
$(".btn").click(function(){
// alert the id value
alert($(this).attr("data-id"))
});
</script>

TA貢獻1846條經驗 獲得超7個贊
我找到了基于 Agus Friasana 方法的解決方案:
$(".btn").click(function () {
// to skip the alert from parent modal button
if ($(this).attr("data-id") != undefined) {
alert($(this).attr("data-id").toString());
$.ajax(
{
url: "your url" + $(this).attr("data-id").toString(),
type: "DELETE",
dataType: "text",
success: function () {
alert('success');
},
error: function () {
alert('fail')
}
}
);
}
});
添加回答
舉報