我正在使用 Ajax 调用来加载表格,但我得到空白页作为 Return ,数据未显示在表格 Div 中,
我试过 $('#groupTable').load(data); 也一样,但没有运气,请帮我解决问题。
阿贾克斯调用
$.ajax({
type: "POST",
url: url,
dataType: "json",
data: { groupNames: JSON.stringify(buttonId), page: JSON.stringify(page) },
success: function (data) {
debugger;
$('#groupTable').html(data);
updateGroupButtons();
},
error: function(request, status, error) {
debugger;
$('#groupTable').html(request.responseText);
updateGroupButtons();
}
});
模型
public interface IPagedList : IEnumerable
{
int PageIndex { get; }
int PageSize { get; }
int TotalCount { get; }
int TotalPages { get; }
bool HasPreviousPage { get; }
bool HasNextPage { get; }
string GroupByNames { get; }
Dictionary<string, IEnumerable> Group { get; }
}
控制器
public JsonResult GetGroups(string groupNames, int page = 1)
{
string[] groups=null;
if (!string.IsNullOrEmpty(groupNames))
{
groups = new JavaScriptSerializer().Deserialize<string[]>(groupNames);
}
var model = _unitOfWork.MenuSetRepository.Get().ToPagedList(groups, page, 10);
return Json(model, JsonRequestBehavior.AllowGet);
// return PartialView("GetGroups",model);
}
看法
<div id="groupTable">
<table id="tbl" class="table">
<thead>
<tr>
@foreach (var property in Model.VisibleProperties())
{
<th draggable="true" ondragstart="drag(event)" id="@property.Name"> @property.GetLabel()</th>
}
<th>Actions</th>
</tr>
</thead>
@if (string.IsNullOrEmpty(Model.GroupByNames))
{
int index = 0;
<tbody>
@foreach (var item in Model)
{
ViewData[index.ToString()] = item;
<tr>
@foreach (var property in item.VisibleProperties())
{
<td>
@Html.Display(index + "." + property.Name)
</td>
}
<td>
@{
RouteValueDictionary routevalues = item.GetIdValue();
}
<li>@Html.ActionLink("Edit", "Edit", routevalues)</li>
<li>@Html.ActionLink("Details", "Details", routevalues)</li>
<li>@Html.ActionLink("Delete", "Delete", routevalues)</li>
</td>
</tr>
index++;
}
</tbody>
}
</table>
</div>