New Routes & Html.RouteLink doesn't seem to work...

Last post 05-08-2008 3:55 PM by jkingry. 3 replies.

Sort Posts:

  • New Routes & Html.RouteLink doesn't seem to work...

    04-20-2008, 5:08 AM
    • Loading...
    • cvallance
    • Joined on 03-20-2008, 9:45 AM
    • Posts 26

     Hi all,

    I'm using the latest CTP3 Preview and having problems with the Html.RouteLink entension...

    Here's my code:

     

                //Edit user details
                routes.MapRoute(
                    "UserProfileEdit",
                    "user/profile/edit",
                    new { controller = "user", action = "profileedit" }
                );
       
                <%= Html.RouteLink("Edit your profile", "UserProfileEdit") %>

     

    It seems to just render the link with an empty href atrribute... am I doing something wrong?

    Also, I notice that the Default.aspx route has been removed and the Default.aspx page has a redirect to "~/Home" in the code behind, is this going to be the norm? 

    Thanks,
    Charles
     

  • Re: New Routes & Html.RouteLink doesn't seem to work...

    04-22-2008, 2:43 AM
    • Loading...
    • cvallance
    • Joined on 03-20-2008, 9:45 AM
    • Posts 26

    Anybody...? No? ... Dust?

    Seriously thou... can someone test this out for me, just so I know that it's a problem down my end.

    Thanks! 

  • Re: New Routes & Html.RouteLink doesn't seem to work...

    05-08-2008, 3:45 PM
    • Loading...
    • jkingry
    • Joined on 06-26-2007, 3:50 PM
    • Posts 4

    I have the same issue. I think it's related to this issue on CodePlex

    http://www.codeplex.com/aspnet/WorkItem/View.aspx?WorkItemId=750

     Here's relavent portions of code

    // Global.asax 
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.MapRoute("TestRoute", "Something/Here/{action}/{id}", new { controller = "Test", action = "Foo", id = "" });
    
                routes.MapRoute(
                    "Default",                                              // Route name
                    "{controller}/{action}/{id}",                           // URL with parameters
                    new { controller = "Home", action = "Index", id = "" }, // Parameter defaults
                    new { controller = @"[^\.]*" }                          // Parameter constraints
                );
            }
    // TestController.cs 
        public class TestController : Controller
        {
            public ActionResult Foo(int id)
            {
                return RenderView();
            }
        }
      
    <!-- ~/Views/Home/Index.aspx -->
        <%=Html.RouteLink("Not Working","TestRoute") %>
     
  • Re: New Routes & Html.RouteLink doesn't seem to work...

    05-08-2008, 3:55 PM
    • Loading...
    • jkingry
    • Joined on 06-26-2007, 3:50 PM
    • Posts 4

    I reread ScottGu's post on this and finally caught the fine print

    Note: with this week's source drop you need to pass-in the controller and action parameters (in addition to the Category param) to the Html.RouteLink() helper to resolve the correct route URL to generate.  The ASP.NET MVC Preview 3 drop in a few weeks will not require this, and allow you to use the Html.RouteLink call exactly as I've written it above to resolve the route.

    Which makes "RouteLink" for now less then ideal, guess I'll wait for Preview 3

    This works for me (or at least creates the expected Url)

    <%=Html.RouteLink("Not Working", "TestRoute", new { controller = "Test", action = "Foo" })%>
    

     

     

Page 1 of 1 (4 items)