我有一个隐藏的形式,它做分页, 这是索引文件代码:
<div id="content" class="ta20">
<div class="inner" style="min-height: 700px;">
<div class="row" style="margin-top: 25px;">
<ol class="breadcrumb ta20AdminBC">
<li><a href="@Url.Action("Dashboard", "Account", new { Area = "Admin" })">پنل مدیریت</a></li>
<li class="active">برچسب ها</li>
</ol>
</div>
<div class="row">
</div>
@Html.Partial("_PartialList", Model)
<hr />
</div>
</div>
@section scripts{
@Scripts.Render("~/bundles/jqueryajax")
<script>
$(document).ready(function () {
makeLisClickable();
});
function makeLisClickable() {
$(".clickEnabledPaginationLi").each(function () {
$(this).unbind("click");
$(this).click(function (e) {
liClick($(this), e);
});
});
}
function liClick(selector, e) {
e.preventDefault();
var form = $("form");
var searchKey = selector.data("key");
var searchPage = selector.data("page");
$("#searchKey").val(searchKey);
$("#pageNum").val(searchPage);
form.submit();
$(this).blur();
return false;
}
</script>
}
以下是_PartialList
代码:
<div class="row" id="dataGrid">
<div class="col-md-12 table-responsive">
<table class="table table-striped">
<tr>
<th>
نام برچسب
</th>
<th>
تعداد زیربرچسب ها
</th>
</tr>
@foreach (var item in Model.List)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.SubTags.Count)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
</table>
</div>
@Html.Partial("_PartialPager", Model.PagingInfo)
</div>
@using (Ajax.BeginForm(Model.PagingInfo.Action, Model.PagingInfo.Controller, new AjaxOptions
{
HttpMethod = "POST",
LoadingElementDuration = 100,
LoadingElementId = "loading",
UpdateTargetId = "dataGrid",
OnSuccess = "makeLisClickable"
}))
{
@Html.AntiForgeryToken()
<input type="hidden" id="searchKey" name="key" />
<input type="hidden" id="pageNum" name="page" />
}
如您所见,我已取消绑定元素的先前点击事件, 但是在第一次执行ajax之后,当我点击我在jquery中选择的类时,它会为所有选定的类元素执行两次函数
答案 0 :(得分:1)
好的,我自己解决了, 我在父页面中定义了from,并从部分视图中省略了它。