开发者

ASP.net WebForms - Using GetRouteUrl in markup

开发者 https://www.devze.com 2023-02-17 08:57 出处:网络
I have been trying to figure out how to use the Routing features with ASP.net 4.0 WebForms. I addeda route to my route collection:

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(
        "abou开发者_运维问答t-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>


right syntax

<a href='<%$RouteUrl:routename=about-route %>' runat="server">Homepage</a>
0

精彩评论

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

关注公众号