2

I am trying to load the mvc webgrid through AJAX call. I have an AJAX function in my view which calls a controller action. The data returned from the controller function is populated in the webgrid which is in partial view and rendered in my Index view. If i click on the 2nd page of the populated webgrid, the page reloads and only the partial view is displayed, remaining page is not displayed.Can anyone please tell me how to solve this problem.

Here is my code:My AJAX Call from the Index view

$.ajax(
       {
           url: "ControllerName/AjaxIndex",
           type: "GET",
           async: false,
           contentType: "application/html; charset=utf-8",
           datatype: 'html',
           data: {
               actionvalue: "CloseDefect"
           },
           success: function (data) {

               $("#load-search").hide();
               $("#gridContent").html(data);
               $('.popupLink').click(function () {
                   $('#my-dialog').load(this.href, function () {
                       $(this).dialog('open');
                   });
                   return false;
               });
               $('#TempDataId').hide();
           },
           error: function (e) {

               alert("Error");
               alert(e.toString());
           }
       });

my partial view is rendered in Index View as :

<div id="gridContent">
@{
    Html.RenderPartial("_webgrid", Model);
}

AjaxIndex Method in Controller:

var incidents = _repository.RetrieveCompanyIncidents(crmuser.Id, ParentCustomer);
                    if (incidents != null && incidents.Any())
                    {
                        for (i = 0; i < incidents.Count(); i++)
                        {
                            caseModel.Add(new CaseManagementModel
                            {
                                Title = incidents[i].Title,
                                TicketNumber = incidents[i].TicketNumber,
                                CaseSource = incidents[i].CaseSource,
                                CaseStatus = incidents[i].CaseStatus,
                                StatusReason = incidents[i].StatusReason,
                                CreatedOn = incidents[i].CreatedOn.ToString()
                            });
                        }
                        totalRecord = caseModel.Count();
                        totalPage = (totalRecord / pageSize) + ((totalRecord % pageSize) > 0 ? 1 : 0);
                        caseModel = caseModel.OrderBy(a => a.Title).Skip(((page - 1) * pageSize)).Take(pageSize).ToList();
                    }
                    else
                    {
                    }
                }
                string value = (string)Session["value"];
                ViewBag.TotalRows = totalRecord;
                ViewBag.PageSize = pageSize;
                TempData["UserMessage"] = "Loading...";

                    return PartialView("_webgrid", caseModel);
ekad
  • 14,436
  • 26
  • 44
  • 46
Coder12345
  • 21
  • 2

0 Answers0