Justin Le
Justin Le

Reputation: 693

Order by a date inside of a foreach razor

I have this partial that lists comments out but that looks like this: enter image description here

As you can see, some of these dates are out of order...

is there a way to order by date inside this razor for each?

            <tbody>
            @foreach (var row in Model.*******.******.Where(d => d.Internal_Note == false))
            {
                <tr>
                    <td>
                        @row.Note
                    </td>
                    <td>
                        @row.NoteDT
                    </td>
                </tr>
            }
        </tbody>

Can I just do something like...

        <tbody>
            @foreach (var row in Model.GovernmentGroupApplication.tbl_AppStatusGvtGroup_Note.Where(d => d.Internal_Note == false).OrderBy(d=>model.Date) <--- pseudocode.
            {
                <tr>
                    <td>
                        @row.Note
                    </td>
                    <td>
                        @row.NoteDT
                    </td>
                </tr>
            }
        </tbody>

Upvotes: 0

Views: 421

Answers (1)

Sean T
Sean T

Reputation: 2504

You're correct with OrderBy(), it's just your reference to the date field where you're wrong.

@foreach (var row in Model.GovernmentGroupApplication.tbl_AppStatusGvtGroup_Note.Where(d => d.Internal_Note == false).OrderBy(d=>d.Date))

Upvotes: 2

Related Questions