Проблема:
Это работаю над онлайн-демо, а также над исходным кодом для загрузки. Однако я не могу понять, почему он не работает в моем конкретном проекте с помощью AJAX. В моем проекте он работает методом полной обратной связи, но не Ajax.
Я даже пытался скопировать метод действия Index и Index и _AjaxEmployeeList Просматривает файлы (.cshtml) (кроме .js).
Примечание. В моем решении это не загрузка, как показано в примерах. Кроме того, имя моего контроллера — AdminController, тогда как в примерах это HomeController
В моем решении мне нужно, чтобы он работал методом AJAX, как в примерах.< /p>
Пожалуйста, помогите относительно:
1. Как найти причину, почему он не работает?
2. Как заставить это работать?
.
Код моего решения (который я пытался воспроизвести в своем решении из образец):
Index.cshtml
Код: Выделить всё
@using MvcPaging
@model IPagedList
@{
ViewBag.Title = "MVC 4 Paging With Ajax Bootstrap";
}
Ajax Paging With Bootstrap In MVC 4
The pager also supports area's. @Html.ActionLink("Ajax paging in an area", "Index", "Admin", new { Area = "AreaOne" }, new { @class = "btn btn-success" })
@using (Ajax.BeginForm("Index", "Admin",
new AjaxOptions { UpdateTargetId = "grid-list", HttpMethod = "get", LoadingElementId = "loading", OnBegin = "beginPaging", OnSuccess = "successPaging", OnFailure = "failurePaging" },
new { id = "frm-search" }))
{
[i]
[/i] Search
@{ Html.RenderPartial("_AjaxEmployeeList", Model); }
}
function beginPaging(args) {
// Animate
$('#grid-list').fadeOut('normal');
}
function successPaging() {
// Animate
$('#grid-list').fadeIn('normal');
$('a').tooltip();
}
function failurePaging() {
alert("Could not retrieve list.");
}
Код: Выделить всё
@using MvcPaging
@model IPagedList
ID
Name
Email
Phone
City
@foreach (var item in Model)
{
@item.ID
@item.Name
@item.Email
@item.Phone
@item.City
}
@Html.Raw(Ajax.Pager(
new Options
{
PageSize = Model.PageSize,
TotalItemCount = Model.TotalItemCount,
CurrentPage = Model.PageNumber,
ItemTexts = new ItemTexts() { Next = "Next", Previous = "Previous", Page = "P" },
ItemIcon = new ItemIcon() { First = "icon-backward", Previous = "icon-chevron-left", Next = "icon-chevron-right", Last = "icon-forward" },
TooltipTitles = new TooltipTitles() { Next = "Next page", Previous = "Previous page", Page = "Page {0}." },
Size = Size.normal,
Alignment = Alignment.centered,
IsShowControls = true,
IsShowFirstLast = true,
CssClass = ""
},
new AjaxOptions
{
UpdateTargetId = "grid-list",
OnBegin = "beginPaging",
OnSuccess = "successPaging",
OnFailure = "failurePaging"
}, new { controller = "Admin", action = "Index", employee_name = ViewData["employee_name"] }))
Showing @Model.ItemStart to @Model.ItemEnd
of @Model.TotalItemCount entries
Код: Выделить всё
public class AdminController : Controller
{
private const int defaultPageSize = 3;
private IList allEmployee = new List();
private string[] name = new string[4] { "Will", "Johnny", "Zia", "Bhaumik" };
private string[] phone = new string[4] { "1-274-748-2630", "1-762-805-1019", "1-920-437-3485", "1-562-653-8258" };
private string[] email = new string[4] { "donec@congueelitsed.org", "neque.non@Praesent.co.uk", "et.magna@Pellentesque.ca", "enim.commodo@orci.net" };
private string[] city = new string[4] { "Wigtown", "Malderen", "Las Vegas", "Talence" };
public AdminController()
{
InitializeEmployee();
}
private void InitializeEmployee()
{
// Create a list of 200 employee.
int index = 0;
for (int i = 0; i < 200; i++)
{
var employee = new Employee();
//int categoryIndex = i % new Random().Next(1, 5);
//if (categoryIndex > 3)
// categoryIndex = 3;
index = index > 3 ? 0 : index;
employee.ID = i + 1;
employee.Name = name[index];
employee.Phone = phone[index];
employee.Email = email[index];
employee.City = city[index];
allEmployee.Add(employee);
index++;
}
}
public ActionResult Index(string employee_name, int? page)
{
ViewData["employee_name"] = employee_name;
int currentPageIndex = page.HasValue ? page.Value : 1;
IList employees = this.allEmployee;
if (string.IsNullOrWhiteSpace(employee_name))
{
employees = employees.ToPagedList(currentPageIndex, defaultPageSize);
}
else
{
employees = employees.Where(p => p.Name.ToLower() == employee_name.ToLower()).ToPagedList(currentPageIndex, defaultPageSize);
}
//var list =
if (Request.IsAjaxRequest())
return PartialView("_AjaxEmployeeList", employees);
else
return View(employees);
}
public ActionResult Paging(string employee_name, int? page)
{
ViewData["employee_name"] = employee_name;
int currentPageIndex = page.HasValue ? page.Value : 1;
IList employees = this.allEmployee;
if (string.IsNullOrWhiteSpace(employee_name))
{
employees = employees.ToPagedList(currentPageIndex, defaultPageSize);
}
else
{
employees = employees.Where(p => p.Name.ToLower() == employee_name.ToLower()).ToPagedList(currentPageIndex, defaultPageSize);
}
return View(employees);
}
}

Подробнее здесь: https://stackoverflow.com/questions/238 ... -ajax-form