Jquery 不能解决它。。你是说如果我做了主布局,正确的布局会影响我的局部布局?我有两个布局,一个用于仪表板,另一个用于用户。主要是我用于仪表板的布局。我认为您的上述方法无法达到不重新加载的效果,并且您正在使用ReflectionIT.Mvc.Pagingdll,您需

Jquery 不能解决它。。你是说如果我做了主布局,正确的布局会影响我的局部布局?我有两个布局,一个用于仪表板,另一个用于用户。主要是我用于仪表板的布局。我认为您的上述方法无法达到不重新加载的效果,并且您正在使用ReflectionIT.Mvc.Pagingdll,您需,jquery,asp.net-ajax,razor-pages,asp.net-core-3.0,Jquery,Asp.net Ajax,Razor Pages,Asp.net Core 3.0,不能解决它。。你是说如果我做了主布局,正确的布局会影响我的局部布局?我有两个布局,一个用于仪表板,另一个用于用户。主要是我用于仪表板的布局。我认为您的上述方法无法达到不重新加载的效果,并且您正在使用ReflectionIT.Mvc.Pagingdll,您需要尝试在局部视图中添加一些引用,请参阅:。你给出的代码太混乱了,我建议你参考我的帖子,使用ajax可以完全防止刷新。它没有重新加载,因为我在过滤表单复选框上使用了jQuery,不引人注目。 // GET: Store publi


不能解决它。。你是说如果我做了主布局,正确的布局会影响我的局部布局?我有两个布局,一个用于仪表板,另一个用于用户。主要是我用于仪表板的布局。我认为您的上述方法无法达到不重新加载的效果,并且您正在使用
ReflectionIT.Mvc.Paging
dll,您需要尝试在局部视图中添加一些引用,请参阅:。你给出的代码太混乱了,我建议你参考我的帖子,使用ajax可以完全防止刷新。它没有重新加载,因为我在过滤表单复选框上使用了jQuery,不引人注目。
// GET: Store
        public async Task<IActionResult> Index(List<int> categorySearch, int page = 1)
        {
            var items = await _context.ItEntity.Include(i => i.CaRelation).Include(i => i.FaRelation).Include(i => i.ITImages).ToListAsync();
            var VMItems = new List<ShopVM>();
            items.ForEach(it => VMItems.Add(new ShopVM
            {
                ItemsId = it.Id,
                ITName = it.ITName,
                Description = it.Description,
                CaRelation = it.CaRelation,
                CategoryId = it.CategoryId,
                FaRelation = it.FaRelation,
                FactoryId = it.FactoryId,
                Image = it.ITImages.FirstOrDefault().ImName
            }));
            ViewBag.categoryList = _context.CatEntity.Select(p => new Category
            {
                Id = p.Id,
                CaName = p.CaName,
                IsSelect = categorySearch.Count == 0 ? false : categorySearch.Contains(p.Id)
            });
            var model = PagingList.Create(VMItems.AsQueryable().AsNoTracking().OrderByDescending(s => s.ItemsId), 20, page);
            return View(model);
        }


        // GET: Filter
        [HttpGet]
        public async Task<PartialViewResult> Filter(List<int> categorySearch, int page = 1)
        {
            var items = await _context.ItEntity.Include(i => i.CaRelation).Include(i => i.FaRelation).Include(i => i.ITImages)
                .Where(x => categorySearch.Contains(x.CategoryId) || categorySearch.Count == 0).ToListAsync();
            var VMItems = new List<ShopVM>();
            items.ForEach(it => VMItems.Add(new ShopVM
            {
                ItemsId = it.Id,
                ITName = it.ITName,
                Description = it.Description,
                CaRelation = it.CaRelation,
                CategoryId = it.CategoryId,
                FaRelation = it.FaRelation,
                FactoryId = it.FactoryId,
                Image = it.ITImages.FirstOrDefault().ImName
            }));

        var model = PagingList.Create(VMItems.AsQueryable().AsNoTracking().OrderByDescending(s => s.ItemsId), 20, page);

        var myViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { Model = model };
        PartialViewResult result = new PartialViewResult()
        {
            ViewName = "_SearchPro",
            ViewData = myViewData,
        };

        return result;
@foreach (var item in Model)
{
    <div class="col-lg-3 ftco-animate">
        <div class="product">
            @if (item.Image != null)
            {
                <a asp-controller="Main" asp-action="Product" asp-route-id="@item.ItemsId" class="text-center img-thumbnail img-prod"><img class="img-fluid img-rounded" style="height:300px; cursor:pointer;" src="~/Images/@item.Image" /></a>
            }
            <div class="text py-2 px-3">
                <a asp-controller="Main" asp-action="Product" asp-route-id="@item.ItemsId"><h3 style="width:100%; text-align:center;" id="itemname" class="font-weight-bold">@item.ITName</h3></a>
                <div class="d-flex">
                    <div style="width:100%; text-align:center;" class="pricing">
                        <p style="width:100%; text-align:center;" class=" font-weight-bold price"><span>@item.FaRelation.FaName</span></p>
                    </div>
                </div>
                <hr>
                <p class="bottom-area d-flex">
                    <a href="#" class=" font-weight-bold add-to-cart"><span>@item.CaRelation.CaName<i class="ion-ios-add ml-1"></i></span></a>
                </p>
            </div>
        </div>
    </div>
}
<form id="ProductsFilter" asp-controller="Store" asp-action="Index" method="get">
            <div class="col-lg-10 row">
                @Html.Partial("_SearchPro")
            </div>
        </form>
 services.AddControllersWithViews().AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                options.JsonSerializerOptions.PropertyNamingPolicy = null;
            });
public class HomeController: Controller
{
    private readonly MyDbContext _context;
    public HomeController(MyDbContext context)
    {
        _context = context;
    }
    public async Task<IActionResult> Index()
    {
        return View();
    }
    [HttpPost]
    public async Task<IActionResult> GetData()
    {
        var teachers = await _context.Teachers.ToListAsync();
        return Json(new { data = teachers });
    }
}
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>Index</h1>
@section Scripts{ 
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>
    <script>
        $(document).ready(function () {
            var mytable = $('#example').DataTable({
                "ajax": {
                    "url": '/Home/GetData',
                    "type": "post",
                    "datatype": "json"
                },
                "columns": [
                    { "data": "Id", "autoWidth": true },
                    { "data": "Name", "autoWidth": true },
                ]
            })
    </script>
}
<div class="container">
    <br />
    <div style="width:90%; margin:0 auto;">
        <table id="example" class="table table-striped table-bordered dt-responsive nowrap" width="100%" cellspacing="0">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>Name</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<form asp-controller="Store" asp-action="Filter" data-ajax="true" data-ajax-update="#ProductsFilter" data-ajax-mode="replace" data-ajax-method="post">
..................
</form>

<form id="ProductsFilter" asp-controller="Store" asp-action="Index" method="get">
                .................

</form>
<script src='@Url.Content("~/lib/jquery.js")'></script>
<script src='@Url.Content("~/lib/jquery.unobtrusive-ajax.min.js")'></script>
<script src='@Url.Content("~/lib/jquery.validate.unobtrusive.js")'></script>
<script src='@Url.Content("~/lib/jquery-validation/dist/jquery.validate.js")'></script>
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication_core_mvc.Data;
using X.PagedList;

namespace WebApplication_core_mvc.Controllers
{
    public class HomeController : Controller
    {
        private readonly MyDbContext _context;
        public HomeController(MyDbContext context)
        {
            _context = context;
        }

        private int pageSize = 5;//set pagesize as you wanted
        public async Task<IActionResult> Test()
        {
            return View();
        }
        [HttpPost]
        public async Task<IActionResult> Test(string filter, int? page)
        {
            int selectedPage = page ?? 1;
            var teachers = await _context.Teachers.ToPagedListAsync(selectedPage, pageSize);
            if (!string.IsNullOrEmpty(filter))
            {
                teachers = await _context.Teachers.Where(x => x.Name.Contains(filter) || x.Id.ToString().Contains(filter)).ToPagedListAsync(selectedPage, pageSize);
            }
            return PartialView("_Table", teachers);
        }
    }
}
@{
    ViewData["Title"] = "Test";
    Layout = "~/Views/Shared/_Layout.cshtml";
} 
@section Scripts{
    <script>
        $(function () {
            GetPartial("", 1);
            $("form").submit(function () {
                event.preventDefault();
                GetPartial($("#Text1").val(), 1);
            })
            $(document).on('click', '.pagination li a', function () {
                event.preventDefault();
                GetPartial($("#Text1").val(), $(this).text());
            });
        })
        function GetPartial(filter, page) {
            $.ajax({
                url: "/Home/Test",
                type: "POST",
                data: { filter: filter, page: page }
            })
                .done(function (partialViewResult) {
                    $("#table").html(partialViewResult);
                });
        }
    </script>

}

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<form method="post">
    Search:
    <input id="Text1" type="text" />
    <input id="Button1" type="submit" value="Search" />
    <div id="table"></div>
</form>
@using X.PagedList.Mvc.Core;
@using X.PagedList;
@model IEnumerable<Teachers>;

<table class="table table-bordered">
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.Id</td>
                <td>@item.Name</td>
            </tr>
        }
    </tbody>
</table>

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