ASP.NET MVC-如何使用户确认删除 [英] ASP.NET MVC - how to make users confirm the delete
本文介绍了ASP.NET MVC-如何使用户确认删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
他, 我在此页面上的表格中每个项目旁边都有复选框,并希望允许用户选择其中的一部分并按我的删除按钮.我只是无法提出使确认窗口并仅在按下是"的情况下才提交的jQuery-这是我的页面
He, I have this page where i have checkboxes next to every item in a table, and want to allow the user to select some of them and press my delete button. I just cant come up with the jquery for making the confirm window and submitting only if 'yes' is pushed - this is my page
<%Html.BeginForm(); %>
<%List<ShopLandCore.Model.SLGroup> groups = (List<ShopLandCore.Model.SLGroup>)Model; %>
<%Html.RenderPartial("AdminWorkHeader"); %>
<table width="100%" id="ListTable" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5" class="heading">
<input type="submit" name="closeall" value="Close selected" />
<input type="submit" name="deleteall" value="Delete selected" />
</td>
</tr>
<tr>
<th width="20px">
</th>
<th>
Name
</th>
<th>
Description
</th>
<th width="150px">
Created
</th>
<th width="150px">
Closed
</th>
</tr>
<%foreach (ShopLandCore.Model.SLGroup g in groups)
{ %>
<tr>
<td>
<%=Html.CheckBox(g.Id.ToString()) %>
</td>
<td>
<%=g.Name %>
</td>
<td>
<%=g.Description %>
</td>
<td>
<%=g.Created %>
</td>
<td>
<%=g.Closed %>
</td>
</tr>
<%} %>
</table>
<%Html.EndForm(); %>
请注意,它仅用于应确认的删除操作,而不必用于关闭按钮.
Please note that its only for the delete that it should confirm, and not necessarily for the close button.
推荐答案
只需在页面顶部添加以下内容:
Simply add the following to the head of your page:
<script type="text/javascript">
$(document).ready(function(){
$("input[name='deleteall']").click(function() {
return confirm('Delete all selected elements?');
});
});
</script>
这篇关于ASP.NET MVC-如何使用户确认删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文