【发布时间】:2014-01-20 16:39:30
【问题描述】:
我正在处理这个项目,我需要将分页添加到审核历史记录日志中。我不知道 MVC 是否带有添加分页的标准方式,或者我是否必须安装 NuGet 包。无论如何,这是我到目前为止需要实现分页的审计日志的代码(我为此使用了存储库模式):
在界面中我有这个:
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>
对此的任何帮助或指导将不胜感激。提前致谢!
【问题讨论】: