0

I am trying to click on a link in products.aspx and redirect to another page categories.aspx. When i use {*id} in routing to handle querystring on products.aspx link is not working well. Sending same products.aspx page.

My Routes:

   routes.MapPageRoute("productsgroup", "products/{groupname}/{*id}", "~/products.aspx");
   routes.MapPageRoute("productscat", "products/brand/{bname}", "~/categories.aspx");

Hyperlink in products.aspx page:

<asp:Hyperlink ID="hyper_link" runat="server" NavigateUrl='<% GetRouteUrl("productscat", new {bname=Eval("brand-name").ToString()})%>' Text="Category1"></asp:Hyperlink>

Hyperlink is in a asp:Repeater and Eval() is working fine on a link and link is seems normal, when i click on the hyperlink, url changes but not sending categories.aspx page.

If i delete querystring {*id} and not use than hyperlink works fine.

I am trying to understand why it's happening and what we can do about it.

Hallowen
  • 133
  • 2
  • 14
  • Hi @Hallowen, welcome to SO. Can you please post the resulting HTML? – JuanR Sep 26 '19 at 14:25
  • @JuanR i was testing this thing all day. I found something and updated my question. If target url starts same like /products/.. then it's not sending to the other page. if i change /someother/.. then link is working. There is an issue with that i cound't understand routing well. – Hallowen Sep 27 '19 at 11:00

1 Answers1

0

There is a simple solution. Change route order and your target url and link will work.

routes.MapPageRoute("productscat", "products/brand/{bname}", "~/categories.aspx");
routes.MapPageRoute("productsgroup", "products/{groupname}/{*id}", "~/products.aspx");

Routing thinks target url is "productsgroup" because it knows the url and target url starts like that. Routing waits for the variable and second route like it doesn't exist for routing.

I hope it helps. Cheers.

Hallowen
  • 133
  • 2
  • 14