如何在ASP.NET核心中加载AJAX中的部分视图

发布时间:2022-09-06 / 作者:清心寡欲
本文介绍了如何在asp.net核心中加载AJAX中的部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改按ajax分页时,我希望每行加载我的部分视图。我的部分负责表格中每一行的按钮 我有一个如下的部分视图:
 @model Guid


    

我在我的表中每行使用以下内容:

   
                @foreach (var expertise in Model.List)
                {
                    
                }
            
@Html.DisplayNameFor(c => c.List.FirstOrDefault().Title)
@Html.DisplayFor(c => expertise.Title)

所以我想让AJAX分页,但我不知道如何在AJAX中加载每行的Patial

@section Scripts
{
    @{ await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    
}

推荐答案

如何在AJAX中按行加载此部分

您可以修改代码以动态获取部分视图的html并填充表,如下所示。

$.each(results.list,
    function (i, expertise) {

        //make request to get the html of partial view
        //and generate new rows to populate table

        $.get("/Home/GetPartial/" + expertise.id, function (res) {
            var newrow = "" +
                "" + expertise.title +
                "" +
                "" +
                res +
                "";

            items += newrow;

            if (i == results.list.length - 1) {
                $('#exp').html(items);
            }

        });
    });

控制器操作

[Route("{controller}/{action}/{id:guid}")]
public IActionResult GetPartial(Guid id)
{
    return PartialView("_TableButtonPartial", id);
}

这篇关于如何在ASP.NET核心中加载AJAX中的部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持吉威生活!



[英文标题]how to load partial view in ajax in asp.net core


声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。