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.