【发布时间】:2022-01-11 02:13:58
【问题描述】:
在我的应用程序中,我已将一些信息加载到表格中。
现在我想在用户点击时获取该行的项目 ID。
这里的 Item.Id 是我想要得到的,但这里我没有分配给任何表格行。 (我认为不需要)。
到目前为止,我还创建了 JavaScript,但我被困在 click 事件中获取 id。
你能帮帮我吗?
到目前为止,我是这样做的:
<div class="table-full-width table-responsive">
<table class="table" id="tblParts">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().PartNo)
</th>
<th>
@Html.DisplayNameFor(model => model.First().PartDescription)
</th>
<th>
@Html.DisplayNameFor(model => model.First().PartModel)
</th>
<th>
@Html.DisplayNameFor(model => model.First().AvaQty)
</th>
<th>
@Html.DisplayNameFor(model => model.First().ReOrderQty)
</th>
<th>
@Html.DisplayNameFor(model => model.First().PartCatogary)
</th>
<th>
@Html.DisplayNameFor(model => model.First().LastUpdated)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<a href="#">
@Html.DisplayFor(modelItem => item.PartNo)
</td>
<td>
<a href="#">
@Html.DisplayFor(modelItem => item.PartDescription)
</td>
<td>
<a href="#">
@Html.DisplayFor(modelItem => item.PartModel)
</td>
<td>
<a href="#">
@Html.DisplayFor(modelItem => item.AvaQty)
</td>
<td>
<a href="#">
@Html.DisplayFor(modelItem => item.ReOrderQty)
</td>
<td>
<a href="#">
@Html.DisplayFor(modelItem => item.PartCatogary)
</td>
<td>
<a href="#">
@Html.DisplayFor(modelItem => item.LastUpdated)
</td>
</tr>
}
</table>
这是脚本。它在点击时触发,但我想在用户点击某行时获取项目 ID。
<script type="text/javascript">
$("#tblParts tr").click(function (event) {
alert("Row Clicked");
});
</script>
【问题讨论】:
标签: javascript c# asp.net-mvc razor