Recently, there is a need to work: Users query log file information, view a specific log information, may also view the log date of the other log information list.
To complete this function, I intend to pass two parameters in the URL, one to record this log time, and the other to log the primary key ID, so prepare to route from ASP.net mvc
Start
In the Global.asax file, the default route is as follows.
Routes. Maproute (
"Default",///Routing name
"{controller}/{action}/{id}",//URL
new {controller with parameters) = "Logon", action = " Logon ", id = urlparameter.optional}//parameter default value
);
In this route, you can only pass in one parameter after the action, and you cannot pass in more than one parameter, so you need to increase the routing information.
In the global file, a new route is added, the route name is "DEFAULT1", and the code is as follows
The first route passes two parameters past
routes. Maproute ("Default1",
"{controller}/{action}/{parma1}/{parma2}",
new {controller = "", Action = ""},
new { });
The above route, you can pass in two parameters.
Here, we build a testcontroller, add a test.cshtml page, write the code in TestController, as follows
Public ActionResult Test (string date, string id)
{
viewdata["date" = date;
viewdata["id" = ID;
return View ();
}
Write the following code in the Test.cshtml page
The log time to query is: @ViewData [date]<br/>
the log ID to query is: @ViewData ["id"]<br/>
Run the compiler, and then enter "HTTP://LOCALHOST:11507/TEST/TEST/2013-12-18/5" in the browser, the page appears as follows
The log time to query is: 2013-12-18
The log ID to query is: 5
Now there is a problem, you need to pass in multiple parameters, how to do it. Of course, only the new route "DEFAULT2" is added. The code is as follows
The second route passes multiple parameters, but only after the second underline is obtained the data
routes. Maproute ("Default2",
"{controller}/{action}/{*id}",
new {controller = "", Action = ""}
);
Run the compiler, and then enter "Http://localhost:11507/Test/Test/2013-12-18/5/xianrongbin" in the browser, the page appears as follows
The log time to query is:
The log ID to query is: 2013-12-18/5/xianrongbin
Here we can only get all the parameters behind the action, for this, we could parse out, such as the log time is "2013-12-18", the Log ID is "5", the log operator is "Xianrongbin".
Ok, the whole thing is complete ~ ~ ~