Вот мой HTML-код
@model IEnumerable<Sampletestapp.Data.UserInfo>
@{
ViewBag.Title = "Test";
Layout = "~/Views/Shared/_Layout.cshtml";
WebGrid webGrid = new WebGrid(source: Model, canSort: false, canPage: false);
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
@webGrid.GetHtml(
htmlAttributes: new { @id = "WebGrid", @class = "Grid" },
columns: webGrid.Columns(
webGrid.Column("Id", "Id"),
webGrid.Column("Name", "Name"),
webGrid.Column("Lastname", "Lastname"),
webGrid.Column("City", "City"),
webGrid.Column("Country", "Country"),
webGrid.Column("State", "State")))
<br />
<div class="Pager"></div>
<script src="~/Scripts/ASPSnippets_Pager.min.js"></script>
<script type="text/javascript">
$(function () {
GetUsers(1);
});
function GetUsers(pageIndex) {
$.ajax({
type: "POST",
url: "/Home/AjaxMethod",
data:'{pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: function (response) {
console.log(response);
}
});
};
//your code here
function OnSuccess(response) {
alert('hi');
var model = response;
console.log(response);
var row = $("#WebGrid tbody tr:last-child").clone(true);
$("#WebGrid tbody tr").remove();
$.each(model.users, function () {
var user = this;
$("td", row).eq(0).html(user.Id);
$("td", row).eq(1).html(user.Name);
$("td", row).eq(2).html(user.City);
$("td", row).eq(3).html(user.Country);
$("td", row).eq(4).html(user.State);
$("#WebGrid").append(row);
row = $("#WebGrid tbody tr:last-child").clone(true);
});
$(".Pager").ASPSnippets_Pager({
ActiveCssClass: "current",
PagerCssClass: "pager",
PageIndex: 1,
PageSize: 5,
RecordCount: model.RecordCount
});
}
$("body").on("click", function () {
GetUsers(1);
});
</script>
и код контроллера:
public ActionResult Test()
{
ViewBag.Country = from result in db.tblcountries select result;
ViewBag.City = from result in db.tblcities select result;
List<UserInfo> dummy = new List<UserInfo>();
dummy.Add(new UserInfo());
return View(dummy);
//return View();
}
[HttpPost]
public JsonResult AjaxMethod(int pageIndex)
{
Users usermodel = new Users();
usermodel.PageIndex = pageIndex;
usermodel.PageSize = 10;
usermodel.RecordCount = db.UserInfoes.Count();
int startIndex = (pageIndex - 1) * usermodel.PageSize;
usermodel.users = (from items in db.UserInfoes
select items)
.OrderBy(items => items.Id).Skip(startIndex)
.Take(usermodel.PageSize).ToList();
return Json(usermodel);
}
bt Я получаю внутреннюю ошибку сервера, и она попадает внутрь функции ошибки, поэтому, пожалуйста, подскажите, где я ошибаюсь