Route data RouteData. Values [key],

Source: Internet
Author: User

Route data RouteData. Values [key],

RoutData. values [Key]Only data in the route definition can be obtained. The url parameter data is not included.

Https:// I .cnblogs.com/EditPosts.aspx? Opt = 1

Route: domain name? Between -->EditPosts. aspx

URL parameter :? After -->Opt = 1

 

// Add link on the View page <a href = '@ Url. action ("StudentDetail", "Student", new {id = 1001, age = 20, gender = 1}) '> View Student details </a> // route table routes. mapRoute (name: "Default", url: "{controller}/{action}/{id}", defaults: new {controller = "Home", action = "Index ", id = 10 });

// The mapped address is as follows:
<A href = "/Student/StudentDetail/1001? Age = 20 & amp; gender = 1 "> View student details </a>
// The public ActionResult StudentDetail (int age, int gender) method in the Controller {// The data ViewBag in RouteData is used. id = RouteData. values ["id"]; // The method parameter ing is used. age = age; ViewBag. gender = gender; return View ();} // display in the StudentDetail View <div> @ * output data obtained from the Controller in the View * @ ViewBag. id <br/> @ ViewBag. gender <br/> @ * output directly in the view * @ ViewContext. routeData. values ["controller"] <br/> @ * traverse the view * {foreach (KeyValuePair <string, object> data in @ ViewContext. routeData. values) {var info = data. key + ":" + data. value; @ info @ * display to page * @ <br/>}</div>

1001 //
1
Student
// Because the route has only the following three parameters, the age and gender are not obtained through traversal.
Controller: Student
Action: StudentDetail
Id: 1001

After modifying the routing rule

// Link configuration <a href = '@ Url. action ("StudentDetail", "Student", new {id = 1001, age = 20, gender = 1}) '> View Student details </a> // route rule routes. mapRoute (name: "Test1", url: "{controller}/{action}/{id}/{age}/{gender}", defaults: new {controller = "Home", action = "Index", id = 10 }); // generate a tag <a href = "/Student/StudentDetail/1001/20/1"> View Student details </a> // traverse RouteData. the result of values is as follows: controller: Student action: StudentDetail id: 1001 age: 20 gender: 1

 

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.