1. What is a route?
Routes are mapped to the ProcessingProgram. Simply put, it is the URL address.
2. What is the URL mode?
The URL mode is like the formatting string we often use,
String . Format ( " Hello, {0} " , " Friends in the blog Garden " );
URL mode can also contain text values and variable placeholders (also known as "URL parameters ").The text and Placeholders are in the URL segments separated by the slash (/) characters. Use braces ({And}) to define placeholders.CodeSimilar. The key value in the URL must exist at the same time. It is worth noting that there must be a text value or separator "/" between placeholders, such
{Language}-{country}/{action}
{Controller}/{action}/{ID}
3. Route Detection
Download DLL tools:/files/simcoder/RouteDebug-Binary.zip
(2) Reference routedebug. dll
(3) write the following code in the global. asax file:
Protected Void Application_start ()
{
Arearegistration. registerallareas ();
Registerroutes (routetable. routes );
Routedebug. routedebugger. rewriteroutesfortesting (routetable. routes );
}
The running effect is as follows:
We can clearly see that controller: Home Action: Index ID: Parameter
4. Check the global. asax file again.
Code
Public Static Void Registerroutes (routecollection routes)
{
Routes. ignoreroute ( " {Resource}. axd/{* pathinfo} " );
Routes. maproute (
" Default " , // Route name
" {Controller}/{action}/{ID} " , // URL with Parameters
New {Controller = " Home " , Action = " Index " , ID = Urlparameter. optional} // Default Value
);
}
Default Controller= "Home", Action= "Index", ID=Urlparameter. Optional
MVC blog directory:
I. ASP. NET MVC 2.0
An error occurred while connecting to aspnetdb. MDF after ASP. NET mvc2.0 was installed.
ASP. NET MVC2 video tutorial
MVC2 instance
2. ASP. net mvc routing 1