开发者

ASP.NET 4.0 URL routing with two or multiple querystring parameters

开发者 https://www.devze.com 2023-01-12 06:40 出处:网络
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.

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?


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
    );


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

0

精彩评论

暂无评论...
验证码 换一张
取 消