In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to add custom routes to ASP.NET MVC applications", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to add custom routes to ASP.NET MVC applications" this article.
For some simple asp.net mvc applications, the default routing table is sufficient. However, when you need to create a special route, you need to create a custom route.
Suppose you are in the development of a blog project, and you want to process the user's request address as follows:
/ Archive/12-25-2009
When the user enters this URL, you want to return the blog entry on the date 12-25-2009. In order to implement this route, you need to add a custom route.
In this asp.net mvc application, this method contains a custom route called blog, which can accept url of type / Archive/entydate.
Here we need to put the custom route on top of the default route. If it is upside down, the default routing table will always be requested.
Our custom route will match the url that starts with archive, and the url like the following will be handled by it.
/ Archive/12-25-2009
/ Archive/10-6-2004
/ Archive/apple
The url of the custom route map request is ArchiveController, and the Entry () action is executed. When the entry method is called, entrydate is passed as an argument to the method.
The ArchiveController code is as follows
We can see that the entry method accepts a parameter of type datetime, and the mvc framework is beautiful enough to automatically convert entrydate to datetime type. If the entrydate in url cannot be successfully converted to datetime, an error will be reported.
The above is all the contents of the article "how to add custom routes to ASP.NET MVC applications". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.