Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET路由不工作(仅加载一条路由)_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# ASP.NET路由不工作(仅加载一条路由)

C# ASP.NET路由不工作(仅加载一条路由),c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,当我在Route.config中设置路由时,当我单击母版页上应该转到不同路由的按钮时,它只转到Route.config中的第一条路由 Route.config: // Profile/username/AccountInfo Route routes.MapPageRoute("ProfileAccountDetails", "Account/Profile/{username}/{accountDetails}", "~/Acco

当我在Route.config中设置路由时,当我单击母版页上应该转到不同路由的按钮时,它只转到Route.config中的第一条路由

Route.config:

        // Profile/username/AccountInfo Route
        routes.MapPageRoute("ProfileAccountDetails",
        "Account/Profile/{username}/{accountDetails}",
        "~/Account/Profile/AccountDetails.aspx", true,
        new RouteValueDictionary { 
            { "username", "" },
            { "accountDetails", "" }});

        // Profile/username/Matches Route
        routes.MapPageRoute("ProfileMatches",
        "Account/Profile/{username}/{matches}",
        "~/Account/Profile/Matches.aspx", true,
        new RouteValueDictionary { 
            { "username", "" },
            { "matches", "" }});
母版页.aspx:

<div id="navProfile">
        <ul id="navBarProfile">
            <li class="navItemProfile"><asp:LinkButton runat="server" ID="linkAccountInfo" CssClass="navLink" OnClick="AccountDetails_OnClick">Account Info</asp:LinkButton></li>
            <li class="navItemProfile"><asp:LinkButton runat="server" ID="linkMatches" CssClass="navLink" OnClick="Matches_OnClick">My Matches</asp:LinkButton></li>
        </ul>
    </div>

当我点击匹配链接时,它只加载ACcountDetails.aspx,而不加载匹配项。您的Route.config运行得很好。您添加的路线不正确。您的路由帐户/Profile/{username}/{accountDetails}和帐户/Profile/{username}/{matches}具有相同的格式,这就是为什么两个路由中只有一个有效。例如,Account/Profile/TestUser/me的格式与这两个路由相同。更改一个路由图,例如帐户/{username}/{matches}

@Bob如果您得到答案,请批准任何答案,问题将得到解决。否则其他用户也会持续应答。
    protected void AccountDetails_OnClick(Object sender, EventArgs e)
    {
        RouteValueDictionary parameters = new RouteValueDictionary  
            { 
                {"username", currentUser.Username},
                {"accountDetails", "AccountDetails"}
            };
        VirtualPathData vpd = RouteTable.Routes.GetVirtualPath(null, "ProfileAccountDetails", parameters);
        Response.Redirect(vpd.VirtualPath);
    }
    protected void Matches_OnClick(Object sender, EventArgs e)
    {
        RouteValueDictionary parameters = new RouteValueDictionary  
            { 
                {"username", currentUser.Username},
                {"matches", "Matches"}
            };
        VirtualPathData vpd = RouteTable.Routes.GetVirtualPath(null, "ProfileMatches", parameters);
        Response.Redirect(vpd.VirtualPath);
    }