1

I've been looking around online for a good long while now and I know how to view all items from database. However what I want to do is show the latest three posts (database items) by date it was added.

Here's my code from the controller which shows all the posts on my index view

   public ActionResult index()
   {
       return View(db.posts.ToList());

   }

How can I change this method to do what I want?

3

1 Answer 1

0

Your SQL query that returns the posts should be something like:

SELECT TOP(3) * FROM posts ORDER BY id

id being a primary key.

Then your index() method should display those results.

Hope this is what you're looking for.

Not the answer you're looking for? Browse other questions tagged or ask your own question.