In the Global.asax file, the default route is as follows.
Routes. MapRoute (
"Default",//route name
' {controller}/{action}/{id} ',//URL with parameter
New {controller = "Home", action = "Index", id = urlparameter.optional}//parameter default value
);
Method One:
URL parameters are obtained by means of a get, generally we pass the URL of a certain rule to pass the parameter. such as the following URL.
Http://localhost/contorller/action/id?Params1=a&Params2=b
Note: The"?" Inside the URL cannot be removed .
We can get it in the controller by binding method, the code is as follows:
Public ActionResult Index (Expmodel model, string ID string Params1, string Params2) {
Viewbag.id = ID;
}
Method Two:
Modify the routing rules in MVC3
In Global.asax.cs, modify the routing rule:
Routes. MapRoute ("DEFAULT1",//route name "{CONTROLLER}/{ACTION}/{ID}/{PARMA1}/{PARMA2}",//URL with parameters
);
such as access to the url:http://localhost/contorller/action/id/a/b
Get the same method as above.
ASP. MVC3 multiple parameter methods via URL routing