Structure Problems - Keep variable values when scroll

MiguelBT 96 Reputation points
2021-11-22T10:07:21.267+00:00

Hi

I have the following code to load data (30 to 30) as you scroll the page:

public ActionResult Index(int? pageNum, string searchString, bool checkControle = false)
        {
            pageNum = pageNum ?? 0;
            ViewBag.IsEndOfRecords = false;

            if (Request.IsAjaxRequest())
            {
                var projects = GetIndex(pageNum.Value, searchString, checkControl);
                ViewBag.IsEndOfRecords = (projects.Any());
                return PartialView("SubTable", projects);
            }
            else
            {

                var result = db.toList()

            ProjectData = result.ToList();
            ViewBag.TotalNumberProjects = ProjectData.Count;
            ViewBag.Projects = GetIndex(pageNum.Value, searchStringl, checkControl);

            return View("Index");

            }
        }

        public List<OrdersColorsViewModel> GetIndex(int pageNum, string searchString, bool checkControl = false)
        {   

            ProjectData = result.ToList();
            int from = (pageNum * RecordsPerPage);

            if (!String.IsNullOrEmpty(searchString))
            {              
                // some code...
                return tempList;
            }            

            if (checkControle == false)
            {
               //some code...
                return tempList;
            }     

            else
            {
                var tempList = ProjectData.OrderBy(x => x.order.Order).Skip(from).Take(30).ToList<OrdersColorsViewModel>();
                ViewBag.ModelCount = result.Count();
                return tempList;
            }
        }

jquery in my index:

var url = '@Url.RouteUrl("ProjectDataList")';     
$(window).scroll(scrollHandler);

I think I have a structure problem, so I summarized my code above.

Everything works correctly, I only have one problem when I value my variables string searchString and bool checkControl, but on the second call (srcoll) the value of my variables is cleared

I undestand that when I call my index again, it will give me the original values, will it be a solution to temporarily store this data?

How can i solve this problem in terms of structure?

Thanks for any help.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,248 questions
{count} votes

Accepted answer
  1. MiguelBT 96 Reputation points
    2021-11-29T17:43:26.683+00:00

    Problem solved by inserting the filters in a single variable.

    if (!String.IsNullOrEmpty(searchString))
                 {              
                     ProjectData = // some code...                
                 }            
    
                 if (checkControle == false)
                 {
                    ProjectData = //some code...
                 }     
    
                 var tempList = ProjectData.OrderBy(x => x.order.Order).Skip(from).Take(30).ToList<OrdersColorsViewModel>();
                 return tempList;
    

    Thanks,

    0 comments No comments

0 additional answers

Sort by: Most helpful