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.