2. ASP. net mvc routing 1

Source: Internet
Author: User

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

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.