使用HTML Helper PageListPager刷新桌子,无需刷新页面

发布于 2025-02-04 16:41:35 字数 472 浏览 2 评论 0原文

我有以下代码行,该行使用HTML助手的pagdlistPager

@html.pageDlistPager(model.kyc_paged_list,page => url.action(“ clientdetails”(“ clientdetails”),new {id = viewBag。 id,kyc_page = page,transaction_page = model.transaction_page,active =“ kyc”}))

在单击Pager整个页面重新加载时。但是我只希望带有id =“ kyc-History”的表才能刷新。

我知道如何使用JavaScript函数重新加载表,但是我不知道如何从pageDlistPager调用它。 有什么想法,我怎么能称呼它?假设JS函数称为reloAdtable()

I have the following line of code which uses html helper's PagedListPager:

@Html.PagedListPager(Model.kyc_paged_list, page => Url.Action("ClientDetails", new { id = ViewBag.ID, kyc_page = page, transaction_page = Model.transaction_page, active = "kyc" }))

When clicking on the the pager the entire page reloads. But I only want the table with id="kyc-history" to refresh.

I know how to reload the table using a JavaScript function but I don't know how to call it from the PagedListPager.
Any ideas how I can call it? Let's say that the JS function is called reloadTable()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相守太难 2025-02-11 16:41:35

我遇到了同样的问题,这篇文章(由安德斯·莱贝克(Anders Lybecker)完成)帮助了我,现在一切正常!
步骤非常清楚,但是请确保在开始之前备份!

看看:
ajax ajax ajax ajax for ASP的分页。 net MVC站点

总而言之,您在控制器中以2个视图1的页面为“控制器”(在我的情况下是索引视图),其中包含page> pagdlistPager Control(Control)的另一个列表(列表视图)。并将列表视图放入索引视图中。并在索引视图中为PagedListPager编写jQuery代码。

您可以阅读文章以获取详细信息!

这是我的代码,还有一些额外的内容,我注意到可以为您提供更多帮助:

列表视图:

@model IPagedList<StudentRegSys.Models.Student>
@{
    Layout = null;
}

@using PagedList.Mvc;
@using PagedList;

<link href="https://fonts.googleapis.com/css?family=Open+Sans:400italic,400,600,700" rel="stylesheet">
@Styles.Render("~/template/css")

<div class="container">
    <div class="row">

          <!-- The List Code-->

        <div class="pagination-control">
            @Html.PagedListPager(Model, i => Url.Action("List", "Home", new { i, search = Request.QueryString["search"] }))
        </div>
    </div>
</div>
@Scripts.Render("~/template/js")

注意:确保制作layout = null;,然后放置样式链接&amp;在此观点中,脚本手册避免了设计问题。

在控制器中:(在我的情况下为Home Controller)

// GET: /Home/Index
public ViewResult Index()
{
    return View();
}

// GET: /Home/List
public ActionResult List(int? i, string search = "")
{
    try
    {
        var students = _context.Student.Include(s => s.Major)
            .OrderBy(s => s.Name)
            .Where(s => s.Name.Contains(search) || s.Major.Name.Contains(search) ||
            s.Address.Contains(search) || s.Phone.Contains(search))
            .ToList().ToPagedList(i ?? 1, 8);


        return View(students);
    }
    catch (Exception)
    {
        return HttpNotFound();
    }
}

索引视图:

@{
    ViewBag.title = "Home";
}

<section id="intro">
    <!-- Some Code -->
</section>

<section id="maincontent">

    @Html.Action("List") <!-- to call the List view --> 

</section>

    <script>
    $(document).ready(function () {
        $(document).on("click", ".pagination-control a[href]", function () {
            $.ajax({
                url: $(this).attr("href"),
                type: 'GET',
                cache: false,
                success: function (result) {
                    $('#maincontent').html(result);
                }
            });
            return false;
        });
    });
    </script>

注意:确保将HTML(结果)放在我的情况下列表的根容器中; 。

希望这对您有帮助:)

I was having the same problem and this article (done by Anders Lybecker) helped me out and now everything working!
It's very clear with steps, But make sure to make backup before starting!

Take a look:
AJAX paging for ASP.NET MVC sites

In summary you make 2 Action Results in your Controler with 2 Views 1 for your page (in my case it's Index View) the other for the List that contain the PagedListPager control (List View). And put the list View inside the Index View. And write the JQuery code for the PagedListPager in the Index View.

You can read the article for the details!

And this is my code with a little extra things I noticed to help you more:

The List View:

@model IPagedList<StudentRegSys.Models.Student>
@{
    Layout = null;
}

@using PagedList.Mvc;
@using PagedList;

<link href="https://fonts.googleapis.com/css?family=Open+Sans:400italic,400,600,700" rel="stylesheet">
@Styles.Render("~/template/css")

<div class="container">
    <div class="row">

          <!-- The List Code-->

        <div class="pagination-control">
            @Html.PagedListPager(Model, i => Url.Action("List", "Home", new { i, search = Request.QueryString["search"] }))
        </div>
    </div>
</div>
@Scripts.Render("~/template/js")

Note: Make sure to make Layout = null; and put the Styles Links & the Scripts manual in this View to avoid design issues.

In the Controller: (it's Home Controller in my case)

// GET: /Home/Index
public ViewResult Index()
{
    return View();
}

// GET: /Home/List
public ActionResult List(int? i, string search = "")
{
    try
    {
        var students = _context.Student.Include(s => s.Major)
            .OrderBy(s => s.Name)
            .Where(s => s.Name.Contains(search) || s.Major.Name.Contains(search) ||
            s.Address.Contains(search) || s.Phone.Contains(search))
            .ToList().ToPagedList(i ?? 1, 8);


        return View(students);
    }
    catch (Exception)
    {
        return HttpNotFound();
    }
}

The Index View:

@{
    ViewBag.title = "Home";
}

<section id="intro">
    <!-- Some Code -->
</section>

<section id="maincontent">

    @Html.Action("List") <!-- to call the List view --> 

</section>

    <script>
    $(document).ready(function () {
        $(document).on("click", ".pagination-control a[href]", function () {
            $.ajax({
                url: $(this).attr("href"),
                type: 'GET',
                cache: false,
                success: function (result) {
                    $('#maincontent').html(result);
                }
            });
            return false;
        });
    });
    </script>

Note: Make sure to put the html(result) in the root container of the list in my case was <section id="maincontent">.

Hope this help you out :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文