我在 Razor 代码中有一个带有标签的表格,该标签与表格中的每条记录一起呈现。当用户单击此图像时,我努力寻找方法,应用程序针对单击的行(在 jquery 中)和警报 ID 获取商店 ID。
<table id="grid">
<thead>
<tr>
<th data-field="store_id">Store ID</th>
<th data-field="address">Address</th>
<th data-field="postcode">post Code</th>
<th data-field="city">City</th>
<th data-field="country">Country</th>
<th data-sortable="false">Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem=> item.storeID)</td>
<td>@Html.DisplayFor(modelItem=> item.address)</td>
<td>@Html.DisplayFor(modelItem=> item.postcode)</td>
<td>@Html.DisplayFor(modelItem=> item.city)</td>
<td>@Html.DisplayFor(modelItem=> item.Country)</td>
<td><img class="img" src="~/Images/delete.png" /></td>
<!-- <td> <input type="button" class="b1" value ="Press Me" /></td>-->
</tr>
}
</tbody>
</table>
这是使用 jQuery 的 javascript 代码
<script>
$(document).ready(function () {
$(".img").click(function () {
var a = $(this). ?????
alert("clicked " + a);
var store = { storeID: '3' }
$.ajax({
type: "POST",
url: "/Master/processJsonRequest",
data: JSON.stringify({ model: store }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (response) {
alert(response);
}
});
});
});
</script>