© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
XD

❔ How can I sort my list by day? Razor Pages

The user is able to log and track habits, and I want they to be able to sort their habits in a way like this: - Today - Yesterday - Search for specific date

So I had this idea:

First add this button:

<form method="post">
        <div class="form-group">
            <input type="submit" value="Sort by date" class="btn btn-success" />
        </div>
    </form>
<form method="post">
        <div class="form-group">
            <input type="submit" value="Sort by date" class="btn btn-success" />
        </div>
    </form>


Then, for the post method (just added the code for sorting habits added today to test first):

public IActionResult OnPost()
        {
            HabitLogs = GetAllLogs();

            HabitLogs = HabitLogs.Where(x => x.Date.Day == DateTime.Now.Day).Select(x => x).ToList();

            return Page();
        }
public IActionResult OnPost()
        {
            HabitLogs = GetAllLogs();

            HabitLogs = HabitLogs.Where(x => x.Date.Day == DateTime.Now.Day).Select(x => x).ToList();

            return Page();
        }


The problem comes when I press the button. I get an ArgumentNullException right at the line where my ImagePath variable is declared (I guess it is because I removed one of the records from HabitLogs):

https://pastebin.com/3c6kN1E8

Any advice on how can I sort this list? I'm a beginner in Razor Pages
Pastebin
H - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ razor pages List custom class
C#CC# / help
3y ago
✅ List.Sort()?
C#CC# / help
15mo ago
❔ Razor pages redirect
C#CC# / help
4y ago
❔ Razor pages view
C#CC# / help
4y ago