question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dealing with a small number of items

See original GitHub issue

Hi,

I was trying out my project asp core 1.1 so I’m using 1.1.4 package… I found this bug:

If you put small number of items like this:

private void InitializeProducts()
		{
			for (var i = 0; i < 7; i++) // <=========== JUST 7 items 
			{
				var product = new Product();
				product.Name = "Product " + (i + 1);
				var categoryIndex = i % 4;
				if (categoryIndex > 2)
				{
					categoryIndex = categoryIndex - 3;
				}
				product.Category = allCategories[categoryIndex];
				allProducts.Add(product);
			}
		}

It won’t show anything on the page and the list will be empty.

My controller action looks like this:

public IActionResult Index(int? page)
		{
			var currentPageNum = page.HasValue ? page.Value : 1;

			var model = allProducts.ToPagedList(currentPageNum, 10);

			return View(model);
		}

*P.S: different kind of issue appears if you put 15 items.

Hope there is a fix (something like 1.1.5) for people who still use asp core 1.1.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
joeaudettecommented, Dec 15, 2017

The way I would do it is make your method GetAgentStudents return Paged Result of T of your model. ie pass in pagenumber and pagesize as params and only retrieve one page of data at a time from the db.

0reactions
yaseralnajjarcommented, Dec 15, 2017

I reproduced it in the attachment. Pagination.zip

My actual code is projecting data then making a PagedList:

public async Task<IActionResult> Index(string searchTerm = null, int page = 1)
		{
			ViewBag.SearchTerm = searchTerm;

			var agent = await _userManager.GetUserAsync(User);

			var identity = (ClaimsIdentity)User.Identity;
			var claimsPrincipal = new ClaimsPrincipal(identity);

			var students = _agentStudentService.GetAgentStudents(agent, claimsPrincipal)
								.FilterByNameOrEmail(searchTerm)
								.ToStudentDetailsViewModels(_environment);

			var result = students.ToPagedListViewModel(page, 5);

			return View(result);
		}

Where students is an IQueryable of StudentDetailsViewModel.

Do you suggest any other better approach?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subitizing - Wikipedia
Subitizing is the rapid, accurate, and confident judgments of numbers performed for small numbers of items.
Read more >
The (F)Law of Small Numbers and What to Do About It
How to Deal with Small Numbers · Suggestion #1: Reduce Reporting Frequency · Suggestion #2: Use a Simple Moving Average · Suggestion #3:...
Read more >
Too Much Stuff, Not Enough Space? Try the 4-Box Technique
Do you have too much stuff and not enough space? Implement this straight-forward decluttering technique to get on top of the problem.
Read more >
Dyscalculia: What It Is, Causes, Symptoms & Treatment
Identifying small quantities of items just by looking (this looks like needing to count each one by one). Doing simple calculations from memory....
Read more >
Hoarding disorder
A hoarding disorder is where someone acquires an excessive number of items and stores them in a chaotic manner, usually resulting in unmanageable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found