如何在使用路由网页时获取某些页面 [英] How to get certain pages when using routing webpages

查看:116
本文介绍了如何在使用路由网页时获取某些页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有页面都可以正常使用路由,但是当选择菜单项(在母版页中)去页面时,它不会转到所选页面。当我进入产品页面,路径为localhost:3806 / yarrow / Products / 35然后点击home menuitem,它给我这条路径localhost:3806 / yarrow / Products / Default.aspx但是正确的路径是localhost:3806 / yarrow / Default。 ASPX。请问如何解决?



我的示例代码

All pages work correctly with routing but when selecting a menuitem (in masterpage) to go a page, it does not go to the selected page. When I enter product page with path localhost:3806/yarrow/Products/35 then click on home menuitem, it gives me this path localhost:3806/yarrow/Products/Default.aspx but correct path is localhost:3806/yarrow/Default.aspx. How to fix it please?

My sample code

Sub RegisterRoutes(routes As System.Web.Routing.RouteCollection)
    routes.MapPageRoute("", "{DesignerID}", "~/PDesigners.aspx")
    routes.MapPageRoute("", "Products/{ProductID}", "~/Product.aspx")
End Sub

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs on application startup
    RegisterRoutes(System.Web.Routing.RouteTable.Routes)
End Sub





此代码在我的用户控件中动态获取id





This code in my user control to get id dynamically

<a href='<%# GetRouteUrl("",new with {.ProductID=Eval("ProductID")})%>' class="product-image">
           <img src='UploadedImages/Products/big/<%# EVAL("PictureID")%>' alt='<%# Eval("ProductTitle") %>'
               width="165" height="161" />
       <asp:Label ID="ProductImageLabel" runat="server" Text='<%# Eval("PictureID") %>' Visible="false" />
       </a>

推荐答案

我会恭敬地提交localhost:3806 / yarrow / Default.aspx事实上,它不是正确的道路,而另一条道路则是。我还认为如果您只是删除波浪号(〜),您的代码可能会按原样运行。
I would respectfully submit that localhost:3806/yarrow/Default.aspx is not, in fact, the correct path, and that the other is. I also think that your code may work as-is if you simply remove the tildes (~).


这篇关于如何在使用路由网页时获取某些页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆