In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail about the operation of the display list and detailed pages in ASP.NET MVC 2.0. the content of the article is of high quality, so the editor will share it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Create View views Index and NewsDetails
Create a news home page to display a list of news.
Under the Views/News directory, right-click, select Add- > View, and modify the configuration as shown in the following figure
Make changes to the presentation in the generated HTML code. The main code is as follows:
| | |
Use the Foreach loop to traverse the records in the news List.
This connection URL will find the NewsDetails Action method under the current Controller and pass the value with the news number Id as the parameter.
The same way to create a news detail page view NewsDetails.asp
The core code generated is as follows:
Detailed news headlines creation time news content
| |
| this connection jumps to the news editor page, and the value is also passed with the news number Id.
Modify the Controller file
Under the Controllers/News file
Modify the method of Action Name=Index so that the Index.aspx page initializes the data, where the database is not read, but some data is forged and put in static variables:
Public static List newsList
The Index Action code is as follows:
Public ActionResult Index () {newsList= new List (); for (int I = 0; I
< 10; i++) { THelperMVC.Models.News.NewsModel news=new THelperMVC.Models.News.NewsModel(); news.Id = i; news.Title = "Title" + i.ToString(); news.CreateTime = System.DateTime.Now; news.Content = "Content 新?闻?内¨²容¨Y" + i.ToString(); newsList.Add(news); } return View(newsList); } 使用For循环生成10条新闻记录。 修改NewsDetails.Aspx所对应的Action方法,如下 // GET: /News/Details/5 public ActionResult NewsDetails(int id) { THelperMVC.Models.News.NewsModel news=newsList[id]; return View(news); } 根据URL传过来的参数(即新闻编号Id),从全局静态变量中寻找NewsModel实体,从而初始化新闻详细页面。 ***修改母版页中的,News连接,如下图所示: 此时,点击首页的News超链接,会寻找NewsController文件夹下的Index方法,从而初始化Views/News/Index.aspx页面。 程序运行效果 按下Ctrl+F5运行程序,如下图所示:Click the [News] hyperlink in the above figure to jump to the news list page, as shown in the following figure:
Click the details hyperlink to jump to the details page of the corresponding record, as shown in the following figure:
So much for the operation of displaying lists and detailed pages in ASP.NET MVC 2.0. I hope the above content can be of some help and can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.