Skip to content

paging and search with ajax and partial view in core

I’m using .net core 6 and I have a table that has pagination and if the table page changes, it refreshes the page I want to change the table page without refresh using partialview and Ajax


        public ActionResult Index(int pageId = 1)
            UsersForAdminViewModel usersForAdminViewModel=_userService.GetAllUsers(pageId);
            return View(usersForAdminViewModel);


        public UsersForAdminViewModel GetAllUsers(int pageId = 1)
            IQueryable<User> result = _context.Users;
            int take = 1;
            int skip = (pageId - 1) * take;

            UsersForAdminViewModel usersForAdminViewModel = new UsersForAdminViewModel();
            usersForAdminViewModel.CurrentPage = pageId;
            usersForAdminViewModel.PageCount = result.Count() / take;
            usersForAdminViewModel.Users = result.OrderByDescending(d => d.RegisterDate).Skip(skip).Take(take).ToList();
            return usersForAdminViewModel;


@model UsersForAdminViewModel

<table class="table table-striped table-bordered table-hover">
        @foreach (var item in Model.Users)
                        <img src="/Images/UserAvatars/Thumb/@item.UserAvatar"/>

                    <a asp-action="Details" asp-route-id="@item.UserId" class="btn btn-outline btn-warning">Details</a>
 <ul class="pagination">

            @for (int i = 1; i <= Model.PageCount; i++)
                    <li class="paginate_button" aria-controls="dataTables-example" tabindex="0">
                        <a asp-action="Index" asp-route-pageId="@i">@i</a>

Can you tell me how to do this?



Could you show your codes about partialview ?

the script could like below:

    $(document).ready(function () {
        $("#btRefresh").click(function () {
                type: "POST",
                url: "/Test/TestRefresh",
                success: function (data) {
                error: function (msg) {
                    alert('error´╝Ü' + msg);



        public ActionResult TestRefresh()
            return PartialView("PartialName", somelist);