How to order a dropdown list items in revers direction?

62 Views Asked by At

I use the following code to read data from database and demonstrate them in a dropdown list:

@{
int m = 1;
foreach (var item in Model.MessagesList)
{
    if (@item.receiverUserId == userId)
    {
        <li>
            <a class="dropdown-item message-item" asp-controller="Messages" asp-action="Index" id="msg-@m"> @Model.UsersList.Where(x => x.Id == item.senderId).Select(x => x.department).First()</a>
        </li>
        m++;
    }
}

}

I want to revers the order of items. What is the best method?

1

There are 1 best solutions below

0
JobesK On

if its coming from a DB why not just use Order By?

select val from table ORDER BY val DESC (or ASC)