简体   繁体   中英

Add attribute to pagination url.action?

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.

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;
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM