0

I send a page number to the controller. And I pull the relevant record and make a return view. I send a request to this method with ajax. Since the page is not refreshed after the return view, I cannot print the current records I want on the page. How can I solve this problem?

Controller;

`  public IActionResult Index(int pageNumber = 1)
    {
        _leadDataPagerInputModel.PageNumber = pageNumber;
        _leadDataPagerInputModel.PageSize = 10;


        ResponseModel<LeadDataDto> responseModel = new ResponseModel<LeadDataDto>();
        IResultObjectPagedListModel<LeadDataDto> leadDataResult = _leadDataBusinessManager.GetList(_leadDataPagerInputModel);
        if (leadDataResult.IsSuccess)
            responseModel.Items = leadDataResult.Data;

        responseModel.Success = leadDataResult.IsSuccess;
        responseModel.ErrorMessage = leadDataResult.Message;

        return View(leadDataResult);
    }`

` onPageClick: function (pageNumber, event) {

           $.ajax({
        type: "POST",
               url: "@Url.Action("Index")",
               data: { pageNumber: pageNumber },
               success: function (result) {

                 

        },
        error: function (req, status, error) {
            alert(error);
        }
    });`

Index.cshtml modal

I want new data to come with the page number I sent, but I don't know how to refresh the data on the page.

Emre Serper
  • 1
  • 1
  • 4
  • When you make the Ajax call to your controller action, it will return the entire HTML for the newly rendered page -- that HTML should be in the variable `result` in the `success` method when the Ajax call completes. It is a best practice to segregate your Ajax controller actions from the ones that are non-Ajax but that's a story for another post. Please look at the following post for some guidance on "**How to replace the entire html webpage with ajax response?**" https://stackoverflow.com/questions/33914245/how-to-replace-the-entire-html-webpage-with-ajax-response – David Tansey Feb 04 '23 at 19:12

0 Answers0