ASP. NET MVC marks the latest published news or articles

Source: Internet
Author: User

A Web site, a list of articles or news lists, need to place a small new.gif in front of the title, marked as the latest news or article. The practice of insus.net today is to implement this functionality in an ASP. NET MVC application. The plan is implemented using three different methods.

Start with the database, create a table, add some data, and create a stored procedure that gets all the records:

In an MVC application, create the model:


Create an entity that interacts with the data to obtain information:

In control, create an action:

In the following directory, create the view:


Newslist.cshtml View:

This is a way of looking at the effect:

The second approach, Insus.net, uses a HtmlHelper extension method to implement this image:

In the view, you need to modify the code a little bit:

At run time, the effect is displayed just as the first method renders.

And the third method? Can be implemented using a partial view.

To use this partial view, you need to modify the newslist.cshtml view:

Run the results, all the same, you think which method is good and convenient, whichever you choose.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.