ASP. net mvc marks the latest news or articles

Source: Internet
Author: User

In the web site of the development, a small new.gif thumbnail is placed in front of the webpage, marked as the latest news or articles. Today's Insus. NET exercise is to implement this function in asp.net mvc applications. It is planned to be implemented in three different ways.

First, create a table from the database, add some data, and create a stored procedure for getting all records:

In the MVC application, create a model:


Create an Entity to interact with the data. obtain the information:

 

In control, create operation:

 

Create a view in the following directory:


NewsList. cshtml View:

 

This is a way to view the effect:

 

Method 2: Insus. NET uses an HtmlHelper extension method to implement this image:

 

In the view, You Need To slightly modify the code:

 

During running, the display effect is the same as that of the first method.

What about the third method? You can use a partial view.

 

To use this part of the view, you need to modify the NewsList. cshtml View:

 

The running results are the same. Which method do you think is good and convenient.

 

Related Article

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.