ASP.net的WebForms - 在标记使用GetRouteUrl [英] ASP.net WebForms - Using GetRouteUrl in markup

查看:136
本文介绍了ASP.net的WebForms - 在标记使用GetRouteUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出如何使用路由与ASP.net 4.0 WebForms的功能。
我添加了一个路线,我的路由集合:

 无效的Application_Start()
{
    的RegisterRoutes(RouteTable.Routes);
}无效的RegisterRoutes(RouteCollection路线)
{
    routes.MapPageRoute(
        有关路由
        关于/,
        〜/ About.aspx
    );
}

在我的母版页我试图做到以下几点:

 < ASP:超链接ID =ASDF=服务器NavigateUrl ='<%= GetRouteUrl(关于路由,新{})%>' >测试与LT; /航空自卫队>

我得到一个编译器错误:服务器标记不能包含<%...%>构造

什么是建立在Web窗体的服务器控件的URL路径的正确方法?我也需要把它列入以下内容:

 < ASP:菜单ID =NavigationMenu=服务器的CssClass =菜单的EnableViewState =假IncludeStyleBlock =false的方向=横向>
    <项目>
        < ASP:菜单项NavigateUrl =途经此地的文本=家/>
        < ASP:菜单项NavigateUrl =途经此地的文本=关于/>
    < /项目>
< / ASP:菜单>


解决方案

有是使用标记路线一种特殊的语法:<一href=\"http://msdn.microsoft.com/en-us/library/dd329551.aspx#Y800\">http://msdn.microsoft.com/en-us/library/dd329551.aspx#Y800

 &LT; ASP:菜单项NavigateUrl ='&LT;%$ RouteUrl:约路由%GT;'文本=关于&GT;&LT; / ASP:菜单项&GT;

I have been trying to figure out how to use the Routing features with ASP.net 4.0 WebForms. I added a route to my route collection:

void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);
}

void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute(
        "about-route",
        "about/",
        "~/About.aspx"
    );
}

In my master page I tried to do the following:

<asp:HyperLink ID="asdf" runat="server" NavigateUrl='<%= GetRouteUrl("about-route", new {}) %>'>Test</asdf>

I got a compiler error: Server tags cannot contain <% ... %> constructs.

What is the proper way to create a route URL in a server control in Web Forms? I also need to include it in the following:

<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
    <Items>
        <asp:MenuItem NavigateUrl="ROUTE HERE" Text="Home"/>
        <asp:MenuItem NavigateUrl="ROUTE HERE" Text="About"/>
    </Items>
</asp:Menu>

解决方案

There is a special syntax for using routes in markup: http://msdn.microsoft.com/en-us/library/dd329551.aspx#Y800

<asp:MenuItem NavigateUrl='<%$RouteUrl:about-route%>' Text="About"></asp:MenuItem>

这篇关于ASP.net的WebForms - 在标记使用GetRouteUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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