0
我已經在我的asp.net mvc中安裝了PagedList.mvc分頁庫。我已經添加下面的腳本: -Ajax Paging不能在我的asp.net mvc web應用程序中工作
var getPage = function() {
var $a = $(this);
var options = {
url: $a.attr("href"),
type: "get"
};
$.ajax(options).done(function (data) {
var target = $a.parent("div.pagedList").attr("data-tms-target");
$(target).replaceWith(data);
});
return false;
};
$(".main-content").on("click", ".pagedList a", getPage);
和主視圖看起來: -
@model IPagedList<TMS.Models.AuditInfo>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div id="AuditTable">
@Html.Partial("_AuditTable", Model)
</div>
和_AuditTable部分觀點是: -
@model IPagedList<TMS.Models.AuditInfo>
<div class="row-fluid sortable" >
<div class="box span12">
<div class="box-header well" data-original-title id="auditlist">
<h2><i class="icon-home"></i> Audit Info </h2>
<div class="box-icon">
<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div><div class="box-content">
<div class="pagedList" data-tms-target="#AuditTable">
@Html.PagedListPager(Model , page => Url.Action("Index",new { page }),
PagedListRenderOptions.ClassicPlusFirstAndLast)
</div>
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>
User Name
</th>
<th>
Audit Action
</th>
<th>
Technology Type
</th>
<th>
Technology
</th>
<th>
Date Time Start
</th>
<th>
Date Time End
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@item.UserName
</td>
<td>
@(item.AuditAction == null ? "None" : item.AuditAction.Name)
</td>
<td>
@(item.TechnologyType == null ? "None" : item.TechnologyType.Name)
</td>
<td>
@Html.DisplayTextFor(_ => item.Technology.TechnologyID).ToString()
</td>
<td>
@Html.DisplayFor(model=>item.DateTimeStart)
</td>
<td>
@Html.DisplayFor(model=>item.DateTimeStart)
</td>
</tr>
}
</tbody>
</table>
</div></div></div>
但問題是,當我點擊一個頁面鏈接時,什麼都不會發生,儘管鏈接的href將指向正確的鏈接,但是如果我點擊鏈接,鏈接將不會加載,而如果我右鍵單擊鏈接並單擊打開它將會打開日e頁。所以我怎麼能克服這個問題呢?
最後的操作方法是: -
public ActionResult Index(int page = 1)
{
var audit = auditinfoRepository.AllIncluding(auditinfo => auditinfo.Technology,auditinfo2=>auditinfo2.TechnologyType,auditinfo3=>auditinfo3.AuditAction).OrderByDescending(a=>a.DateTimeStart)
.ToPagedList(page,30);
if (Request.IsAjaxRequest())
{
ViewBag.FromSearch = true;
return PartialView("_AuditTable", audit);
}
return View(audit);
}
我已經在我的應用程序中完成了所有這些操作。 –
請檢查jQuery之前是否包含unobtrusive-AJAX腳本,以便您的腳本無法正常工作。你的其他代碼看起來不錯。 – Amol