【问题标题】:Add attribute to pagination url.action?向分页 url.action 添加属性?
【发布时间】:2020-12-28 08:03:18
【问题描述】:

我正在尝试将 ID 之类的属性添加到分页中,以便我可以代表它在 JS 中执行一些操作。

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

当我尝试添加它时,它会显示在 URL 中。有谁知道在这种情况下我如何设置ID

对此的任何帮助将不胜感激。

【问题讨论】:

    标签: javascript c# asp.net-mvc mvcrazor


    【解决方案1】:

    我想通了。

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

    需要添加ViewContext 才能从viewbag... 中获取ID,并在控制器中再次声明该ID。

    使用 JQuery

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

    jQuery 函数

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

    【讨论】:

    • 我想检测 JS 中的那个 id。当有人点击它时,在 JS 中我必须在它到达控制器之前执行一些操作。
    • 查看我编辑的答案,有关详细信息,您可以从此链接stackoverflow.com/questions/26769933/…获得一个想法
    猜你喜欢
    • 2020-07-09
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多