2

How can I pass two querysting parameters in URL routing using ASP.NET 4.0?

I have gone through many articles, but everywhere it shows only one parameter.

I'd like the display URL to be:

http://www.mywebsite.com/reports/1-this-is-my-first-report

The first parameter is ID: 1
The second is Name: This is my first report

I am trying following route, but it is not working

    routes.MapPageRoute(
       "MarketReports",               // Route name
       "Reports/{*i}-{*n}",  // Route URL
       "~/pageControl2.aspx"      // Web page to handle route
    );

How can I make this work as described?

2 Answers 2

3

Try formatting the URL this way:

http://www.mywebsite.com/reports/1/this-is-my-first-report

routes.MapPageRoute(
       "MarketReports",               // Route name
       "Reports/{*i}/{*n}",  // Route URL
       "~/pageControl2.aspx"      // Web page to handle route
    );
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Brian, It is working now. but i have one more problem with routing & javascript i am populating javascript menu. It populates wrong reference. How can i generate Rout URL for javascript Menu?
Try: var route = '<%$RouteUrl:locale=CA,year=2009,routename=salesroute%>';
Or try: var r = '<%= RouteTable.Routes.GetVirtualPath(Nothing, "ExpensesRoute", parameters) %>'; which would require an <%@ import statement.
1

Try this

Response.RedirectToRoute("UrlRouting for Querystring", 
    new { name = txtsearchurlrouting.Text,  text = txtsearchid.Text });

In Global.asax

routes.MapPageRoute("UrlRouting for Querystring", 
     "Querystring/Selected/{name}/{text}/", "~/Address.aspx");

like this we can pass multiple querystring parameters

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.