ASP. MVC3 multiple parameter methods via URL routing

Source: Internet
Author: User

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

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.