【发布时间】:2013-04-26 08:24:02
【问题描述】:
我正在开发 MVC 应用程序。 当我单击删除链接时,我想获取记录的 ID。 在警报窗口中,我想显示我删除的记录 ID。
如何做到这一点?
@model PaymentAdviceEntity.CompanyType
<script type="text/javascript">
$(document).ready(function () {
$('.remove').click(function () {
alert(?????);
$(this).parent().parent().remove();
});
});
</script>
<div id='InvoiceList' class='divInvoiceList span12' style='margin-bottom:5px;margin-left:0px;'>
@if (Model != null)
{
<span class="span3" style="margin-left:0px;">@Html.TextBox("InvoiceId", @Model.Name , new { @onkeypress = "return isNumberKey(event)", @onblur = "CalculateNetValue()", @style = "width:75%; text-align:right;", @class = "clsInvoiceId" })</span>
<span class="span1" style="margin-left:0px;padding-top:6px;">@Html.HiddenFor(model=>model.Id) <a href='#' style='font-size:14px;text-decoration:none;font-weight:bold;' id='lnkRemove' class='clsRemove remove'>X</a></span>
}
</div>
我可以看到记录 ID,即 data-id = 4,但在运行应用程序后无法查看以下 HTML 代码。
<span class="span3" style="margin-left:0px;" data-id="4"><input class="clsInvoiceId valid" id="InvoiceId" name="InvoiceId" onblur="CalculateNetValue()" onkeypress="return isNumberKey(event)" style="width:75%; text-align:right;" type="text" value="asdasd"></span>
【问题讨论】:
-
为什么在移除之前不获取 ID 或者只是隐藏而不是移除?
-
我认为您的标记不正确。如果你使用 $(this).parent().parent().remove();您将删除您的父 div,即“InvoiceList”,而不是包含 recordID 的另一个跨度
-
好的,我会检查一下,但我的首要任务是获取跨度的 Id...
-
你想得到哪一个?跨度的 ID 还是文本框的 ID?
-
记录ID,现在我已经写了这段代码...
<span class="span1" style="margin-left:0px;padding-top:6px;">@Html.HiddenFor(model=>model.Id) <a href='#' style='font-size:14px;text-decoration:none;font-weight:bold;' id='lnkRemove' class='clsRemove remove'>X</a></span>
标签: jquery asp.net-mvc asp.net-mvc-3