简体   繁体   中英

Change order of items when on index MVC5 asp.net C#

So I have a question about MVC5.

I want to change the order of items listed on the view. When a new record is created with the create view it automatically puts the new one under the old one when showed on the index view. I want it the other way around. So that the new record which is showing in the view is on top. I have no clue on how to achieve this. Hope someone can help me.

You should have a order column in your table. and order Items by that, this can be an integer, but however I Prefer a datetime type.

If you want to change the order of items just change their order field value. Imagine that you are ordering descending, then setting current datetime to an item will move it to the end.

It is difficult to give a good answer to this question because of the lack of details in the question. Assuming however that you are creating the data in a database and returning a list from there you can add this to the Linq expression providing you with the list

OrderByDescending(x => x.ID)

where ID is the ID of the entity being created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM