C#C
C#3y ago
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>


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();
        }


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
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.
Was this page helpful?