Chapter 2 ASP. net mvc (URL, route, and Region), asp. netmvc

Source: Internet
Author: User

Chapter 2 ASP. net mvc (URL, route, and Region), asp. netmvc
Aspnet mvc url, route and Region 1, URL, route and region

1. configure a vro

1. URL Mode

2. Define the default route Value

3. Use static URLs

4. Route Sequence

5. Custom segment Variables

6. Use the action method parameters

7. Pass parameters through the browser

1. Define a route in the routing table and name the Parameter

2. Obtain the parameter value:

1) through the action Method in the controller, such as List (string cate), the parameter names in the method must be the same as those in the route table, RouteData. values [Key] is obtained. The key is the parameter name. If an object is obtained, it can be implemented through the model binding mechanism.

Ii. Generate the output URLS

1) Static links in the view

1. ActionLink: Corresponding Controller/action, using the default route

Parameter: new {parameter = value ,...}

Style: new {@ class = style name}

2. RouteLink: Use the specified route

Format: <a/>: Controller/Action/Parameter

2) dynamic steering

1. Redirect (url): the parameter is the url address.

2. RedirecrToAction (action, Name, controllerName). The parameters are action names and various control names.

3. RedirectToRoute (routeName, routeValues) to the specified route

RouteName: route name

RouteValues = new {controller = value, action = value, id = value}

2. Combine the content of Chapter 1 MVC to set the product category display. 1. Right-click the "MVCProduct" project and choose "Areas ":

2. Add the "Controller" name "HomeController" to the "Controller" file in the "Areas" file ":

3. Add "Controller" named "HomeController. cs" to "Index ()" in the "Controller" file in the "Areas" file to add a view:

 

3. Set "Route" to add route Parameters ":

4. Add the corresponding "Controller name" to "Route". The name can be found on the "HomeController. cs" page in the "Controller" file:

5. Copy the name and put it in "Routing Parameters" Code example: View Code:

 

6. Add a name classification method Code example in "presentation layer": View Code

:

7. Finally, you can call the method in the "MvcProduct" project. comment out the previous method. Example Code: View Code

 

:

8. Running result: Enter the category name.

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.