Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:39:28+00:00 2026-06-06T04:39:28+00:00

I have run through the MVC3 Razor tutorial on ASP.Net, and and have started

  • 0

I have run through the MVC3 Razor tutorial on ASP.Net, and and have started trying adapt it a bit to work with a small web project of my own.

What I have done so far is create a section that will add two fields to a new database record. A “News_Item” and a “News_Date” field.

Then when displaying this data on a separate page I only want to display the 4 most recently added records.

My View code (below) displays all entries in the database no problem, but I’d like to amend as stated above so it only displays the 4 most recent records. How would I go about doing this please? I am a beginner, and have no real prior experience with development.

In my Controller I have the following code for “Get”:

public ViewResult Index()
{
    return View(db.News_Entries.ToList());
}

and just in case it is needed, here is the Model code:

namespace dale_harrison.Models
{
    public class News
    {
        public int ID { get; set; }
        public string News_Entry { get; set; }
        public DateTime News_Date { get; set; }
    }

    public class NewsDBContext : DbContext
    {
        public DbSet<News> News_Entries { get; set; }
    }
}

Many thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:39:31+00:00Added an answer on June 6, 2026 at 4:39 am

    Change your Actions code

    public ViewResult Index()
    {
        return View(db.News_Entries.OrderByDescending(n => n.News_Date).Take(4).ToList());
    }
    

    you should read linq to entity tutorials

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just getting started on iPhone dev today and have run through Apple's HelloWorld tutorial:
in an ASP.NET MVC3 web application. I have a view. the view has a
I am trying to run jquery through a rails app. I have the edit
I have an ASP.NET MVC 3 web application. I recently installed T4MVC templates by
I have a small app that uses cocos2d to run through four levels of
.NET newbie here. I have an MVC3 web application EF 4.1 Code First and
Ok, little bit of background here. I have a large scale web application (MVC3)
I have a function that is to run through each row of a table,
I have some data which I run through, which generates a textfile. The data
I have several Oracle queries that perform well when run through SQL*PLUS. However when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.