0

im using PagedList with ajax. everything work fine. but the only problem is that the page links are not getting update as i click on them.

this is partial view containing the list

@model IEnumerable<UniProject.Models.Short_Code>
<table class="table table-condensed table-bordered table-hover table-striped">
    <tr>
        <th>
            Shortcode
        </th>
        <th>
            Service
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.ServiceCode)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Service)
            </td>
        </tr>
    }
</table>

this is my view

@model PagedList.IPagedList<UniProject.Models.Short_Code>
@using PagedList.Mvc
<link type="text/css" rel="stylesheet" href="~/Content/PagedList.css" />
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

<div class="col-lg-8">
  <div id="tableDiv">
      @Html.Partial("_shortcode_table" , Model)
  </div> 

<div id="myPager">
    @Html.PagedListPager(
    Model,
    page => Url.Action(
        "Index",
        new
        {
            page = page
        }
    )
  )
 </div>
</div> 


<script>
$(function () {
    $('#myPager').on('click', 'a', function () {
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            success: function (result) {

                $('#tableDiv').html(result);
            }

        });

        return false;
    });
});
</script>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

please help with this issue that where am i doing wrong. any help would be welcome . thanks

  • You have not shown the relevant code (including the controller method) but from your [previous question](http://stackoverflow.com/questions/40211195/i-am-trying-to-have-a-create-form-and-a-list-both-working-with-ajax-without-refr), its because all your doing is updating the `
    ` element, not updating the html generated by `@Html.PagedListPager()`
    –  Oct 24 '16 at 06:48
  • thanks for response, but what should i do now . how to update it? – Mostafa Hakimi Oct 24 '16 at 06:51
  • As I noted on you previous question, you code makes no sense (particularly having a 'Create' form in the same view (what would you expect to happen if the user was on the last page and created a new item?). PagedList.MVC already has ajax functionality - refer [this answer](http://stackoverflow.com/questions/17336165/ajax-pagination-in-pagedlist-mvc-using-partial-page) –  Oct 24 '16 at 06:58
  • yes that is true. now the create form is no longer important forget about it. the pagination also works fine but the only problem is that the page links are not getting updated as i click. – Mostafa Hakimi Oct 24 '16 at 07:13
  • I know - read my first comment. –  Oct 24 '16 at 07:15

0 Answers0