Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在部分视图中使用PagedList和Javascript更新寻呼机_Jquery_Asp.net Mvc_Asp.net Mvc Partialview_Pagedlist - Fatal编程技术网

Jquery 在部分视图中使用PagedList和Javascript更新寻呼机

Jquery 在部分视图中使用PagedList和Javascript更新寻呼机,jquery,asp.net-mvc,asp.net-mvc-partialview,pagedlist,Jquery,Asp.net Mvc,Asp.net Mvc Partialview,Pagedlist,我有一个视图用户,它使用寻呼机调用部分视图_table: <div id="tableWithPagerId"> @Html.Action("LoadUserTable","Controller", Model) </div> 在_tablewith pager的内部,我有其他部分视图_table用户和该表的寻呼机: @model PagedList<user> <div id="TableContainerId">

我有一个视图用户,它使用寻呼机调用部分视图_table:

    <div id="tableWithPagerId">
    @Html.Action("LoadUserTable","Controller", Model)
    </div>
在_tablewith pager的内部,我有其他部分视图_table用户和该表的寻呼机:

@model PagedList<user>
<div id="TableContainerId">
   @Html.Partial("_TableUser");
</div>
<div id="Paginator">
   @Html.PagedListPager( Model, page => Url.Action("LoadUserTable", new { page = page, /*more params...*/ }) )
</div>
一切正常。但是,如果我单击第二个页面,它将正确地呈现在“TableContainerId”表div中,并且不会更新寻呼机。这是个问题。如果我将javascript更改为在“tableWithPagerId”div中呈现,表将被更新,页面将被删除,但我必须再次重新加载javascript

有人知道我该怎么解决这个问题吗?我搜索了如何在加载javascript时将其放入部分视图,以加载脚本,但不起作用


谢谢。

在局部视图中调用将不起作用。 一段时间后,我得到了一个简单的解决方案,效果非常好。只需在重新加载html数据后调用javascript函数。像这样:

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

除了Marco的具体回答外,我还想提出一个总体解决方案:

您可以使用这个javascript库(我编写的):

它解决了重新加载、分页等问题,并且是完全可定制的。它包括文档

它还有一些很好的特性,比如

  • 筛选和排序(首选客户端或服务器端)
  • 去抖动以防止过多的刷新
  • 可自定义的按钮和样式,取决于行数据
  • 轻松地向行添加/删除事件侦听器(并在触发时获取行数据)
注意:使用此库,您将不再使用局部视图

如果您仍在浏览器中开发分页列表,请看一看

$(function() {
    $('#Paginator').on('click', 'a', function() {
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            success: function(result) {
                $('#TableContainerId').html(result);
            }
        });
        return false;
    });
});
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;
    });
});