Add attribute to pagination url.action?

Viewed 261

I am trying to add attributes like ID into pagination so I can perform some actions in JS on behalf of that.

 @Html.PagedListPager(Model, page => Url.Action("ConfirmCases", new { page }))

when I tried to add it shows in the URL. Does anybody know how I can set an ID in this case?

any helps regarding this would be appreciated.

1 Answers

I figured it out.

@Html.PagedListPager(Model, page => Url.Action("ConfirmCases", new { ID = ViewContext.ViewBag.CheckingAccountId, page, PageSize = Model.PageSize } ))

ViewContext needed to be added in order to get the ID from the viewbag... and also declared the id again in the controller.

OR Using JQuery

<div id="Paginator">
@Html.PagedListPager(Model, page => Url.Action("ConfirmCases", new { ID = ViewContext.ViewBag.CheckingAccountId, page, PageSize = Model.PageSize } ))
</div>

Jquery Function

function bind() {
    $('#Paginator').on('click', 'a', function() {
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            success: function(result) {
                $('#TableContainerId').html(result);
                bind(); // called this java script code again
            }
        });
        return false;
    });
});
Related