0
我有我正在處理的這個項目,我需要將分頁添加到審計歷史記錄日誌中。我不知道如果MVC標準的方式來添加分頁,或者如果我將不得不安裝一個NuGet包。無論如何,這裏是我迄今爲止審計日誌,我需要實現分頁的代碼(我使用這個庫模式):ASP.NET MVC分頁
在Interface我有這樣的:
IEnumerable<AuditRecord> GetAuditRecords(Expression<Func<AuditRecord, bool>> filter, Func<IQueryable<AuditRecord>, IOrderedQueryable<AuditRecord>> orderBy = null, int pageIndex = 0, int pageSize = 20);
然後,我有具有這種一個UserHelper:
public AuditInfo GetAuditInfo(SearchInfo searchInfo)
{
AuditInfo auditInfo = new AuditInfo();
if (searchInfo != null)
{
List<AuditRecord> auditRecords =
UserManager.GetAuditRecords(record => record.Username == searchInfo.UserName,
records => records.OrderByDescending(record => record.Date), 0, 100);
auditInfo.AuditRecords = auditRecords;
}
return auditInfo;
}
然後在控制器:
public ActionResult AuditHistory(String username)
{
SearchInfo searchInfo = new SearchInfo { UserName = username };
AuditInfo auditInfo = _userHelper.GetAuditInfo(searchInfo);
return PartialView(auditInfo);
}
最後的觀點:
@if (Model != null && Model.AuditRecords != null && Model.AuditRecords.Count != 0)
{
<table required="False" border="0" class="data_std_results" id="tbl_std_documents">
<thead>
<tr>
<th>
<span class="resulttabletitle">Date</span>
</th>
<th>
<span class="resulttabletitle">Action</span>
</th>
<th>
<span class="resulttabletitle">Application</span>
</th>
<th>
<span class="resulttabletitle">Modified by</span>
</th>
<th>
<span class="resulttabletitle">Response</span>
</th>
<th>
<span class="resulttabletitle"></span>
</th>
</tr>
</thead>
<tbody>
@{
int index = 0;
}
@foreach (var item in Model.AuditRecords)
{
<tr>
<td>@item.Date.ToString()
</td>
<td>@item.ActionKey
</td>
<td>@item.ApplicationName
</td>
<td>@item.Delegate
</td>
<td>@item.Response
</td>
<td>
@if (!string.IsNullOrEmpty(item.Comment))
{
<a href="@string.Format("#comment{0}", index)" class="comment">Details</a>
<div class="showNone">
<div id="@string.Format("comment{0}", index)" class="c_gen_lb_message">
<h3>@string.Format("{0} {1} for {2} at {3}", item.ActionKey, item.Response, item.ApplicationName, item.Date.ToString())</h3>
<h5>
Comments:</h5>
@item.Comment
@if (!string.IsNullOrEmpty(item.Reason))
{
<h5>
Reason:</h5>
@item.Reason
}
<h5>
Ip Address:</h5>
@item.IpAddress
@if (!string.IsNullOrEmpty(item.Delegate))
{
<h5>
Modified By:</h5>
@item.Delegate
}
</div>
</div>
}
</td>
</tr>
index = index + 1;
}
</tbody>
</table>
<div class="clearBoth">
</div>
}
else
{
<p>
no records found</p>
}
<script type="text/javascript">
$(document).ready(function() {
$('#tbl_std_documents').dataTable({
"bFilter": false,
"bPaginate": false,
"bSort": false,
"bInfo": false
});
$("a.comment").fancybox({
'type': 'inline',
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'hideOnContentClick': true,
'speedIn': 600,
'speedOut': 200,
'overlayShow': false
});
});
</script>
任何幫助或指導,將不勝感激。提前致謝!
這是我正在研究的一個選項。 – Skrubb