Home > Software design >  Taking long time to load index page
Taking long time to load index page

Time:07-29

In my ASP.NET MVC project, there are more than 4000 records to be shown on the Index page.

Because the records numbers are high, loading time has gone to more than 4-5 minutes.

Is there any simple way to show all the data in less time?

This is my controller code.

 public ActionResult Index() {

   List < MyRequestViewModel > myRequests = new List < MyRequestViewModel > ();
   var req = (User.Identity as ClaimsIdentity).Claims.Where(c => c.Type == "UserId").FirstOrDefault();
   int EmpId = int.Parse(req.Value);

   if (Lvl != 1) {

     var MyRequests = (from a in db.AppRequest join Rtype in db.Request_Types on a.ReqType equals Rtype.Id join ApState in db.M_ApprovalStatus on a.Approval_Status equals ApState.Id where a.Create_By == EmpId select new MyReq {
       ReqNumber = a.Id,
         ReqType = Rtype.Request_Type,
         CreatedDate = a.Created_Date,
         ReqHeading = a.Req_Heading,
         ReqTimeline = ApState.Approval_Status_Name
     }).ToList().OrderByDescending(x => x.ReqNumber);

     return View(MyRequests);
   } else {
     var MyRequests = (from a in db.AppRequest join Rtype in db.Request_Types on a.ReqType equals Rtype.Id join ApState in db.M_ApprovalStatus on a.Approval_Status equals ApState.Id where a.Status == true select new MyReq {
       ReqNumber = a.Id,
         ReqType = Rtype.Request_Type,
         CreatedDate = a.Created_Date,
         ReqHeading = a.Req_Heading,
         ReqTimeline = ApState.Approval_Status_Name
     }).ToList().OrderByDescending(x => x.ReqNumber);

     TempData["IfsReff"] = TempData["mydata"];
     return View(MyRequests);
   }

 }

This is the View

@model IEnumerable<Asp_PASMVC.ViewModels.MyReq>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

  <div >
    <table id="MyRequest" >
      <thead>
        <tr>
          <th style="width: 1%"> Request Number </th>
          <th> Request Type </th>
          <th> Created Date </th>
          <th> Request Heading </th>
          <th> Request Timeline </th>
          <th></th>
        </tr>
      </thead>
      <tbody> @foreach (var item in Model) { var editClass = item.ReqTimeline == "Department Head" ? "" : "btn-primary disabled"; var ApproveClass = item.ReqTimeline == "Approved" ? "" : "btn-success disabled"; <tr>
          <td> @item.ReqNumber </td>
          <td> @item.ReqType </td>
          <td> @item.CreatedDate </td>
          <td> @item.ReqHeading </td>
          <td> @item.ReqTimeline </td>
          <td> @*@Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-primary pull-right " editClass })*@ <div > @Html.ActionLink("Details", "Details", new { id = item.ReqNumber }, new { @target = "_blank", @class = "btn btn-warning pull-right" }) <button type="button"  data-toggle="dropdown">
                <span >Toggle Dropdown</span>
              </button>
              <div  role="menu">
                <button type="button"  onclick="ViewCanceledReason(@item.ReqNumber)">View canceled reason</button>
              </div>
            </div> @Html.ActionLink("Download Approval", "Download_PDF", "ReportsViewModel", new { id = item.ReqNumber }, new { @target = "_blank", @class = "btn btn-success pull-right"   ApproveClass }) <button onclick="confirmDelete(@item.ReqNumber);" , >Cancel</button>
          </td>
        </tr> } </tbody>
    </table>
  </div>

I'm using a bootstrap pagination table

CodePudding user response:

Instead of loading data using razor you can load data using json and set data to view through JavaScript then You will get the performance very high. Go to this link to see how you can show data.

https://abctutorial.com/post/227/get-user-list-using-aspnet-mvc--jquery--ajax
  • Related