如果以下路线:
routes.MapPageRoute(
"Build", // Route name
"build", // Route URL
"~/build.aspx" // Web page to handle route
);
routes.MapPageRoute(
"Type", // Route name
"build/{type}", // Route URL
"~/build.aspx" // Web page to handle route
);
routes.MapPageRoute(
"Project", // Route name
"build/{type}/{project}", // Route URL
"~/build.aspx" // Web page to handle route
);
routes.MapPageRoute(
"Task", // Route name
"task/{type}/{project}", // Route URL
"~/task.aspx" // Web page to handle route
);
如何在.aspx(不是代码隐藏)中设置超链接导航网址到名为'task'的路由,其中type ='tool'和project ='excel'?
答案 0 :(得分:1)
例如,在网格视图模板字段中:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" ID="btnUp" Text='<%# Eval("ProjectID") %>'
NavigateUrl='<%# GetRouteUrl("Task",
new System.Web.Routing.RouteValueDictionary
{
{"type", "tool" },
{"project" , "excel" }
}) %>' />
</ItemTemplate>
</asp:TemplateField>
或者,您可以从数据源设置参数:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" ID="btnUp" Text='<%# Eval("ProjectID") %>'
NavigateUrl='<%# GetRouteUrl("Task",
new System.Web.Routing.RouteValueDictionary
{
{"type", Eval("Type") },
{"project" , Eval("ProjectType") }
}) %>' />
</ItemTemplate>
</asp:TemplateField>
答案 1 :(得分:0)
您必须设置 RouteName 参数。例如。你可以设置这样的路线:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%$RouteUrl:RouteName=Project, type=1, project=2%>">Type 2</asp:HyperLink>
答案 2 :(得分:-1)
您可以像这样设置路线值
<asp:HyperLink ID="lnk3" runat="server" NavigateUrl="<%$RouteUrl:Name=IPhone,ID=1 %>" Text="IPhone" />
在Global.asax中,我的配置就像这样
RouteTable.Routes.MapPageRoute("StoreRoute",
"BookStore/{Name}/{ID}",
"~/Webpages/BookStore/ViewBookDemo.aspx");