ASP.NET MVC 2 - Custom route doesn't find controller action

Posted by mcfroob on Stack Overflow See other posts from Stack Overflow or by mcfroob
Published on 2010-06-02T18:36:44Z Indexed on 2010/06/02 18:54 UTC
Read the original article Hit count: 199

Filed under:

For some reason my application isn't routing to my controller method correctly. I have a routelink like this in my webpage -

<%= Html.RouteLink("View", "Blog", new { id=(item.BlogId), slug=(item.Slug) }) %> 

In global.asax.cs I have the following routes -

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "MoreBlogs",
        "Blog/Page/{page}",
        new { controller = "Blog", action = "Index" }
    );

    routes.MapRoute(
        "Blog",
        "Blog/View/{id}/{slug}",
        new { controller = "Blog", action = "View"}
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Blog", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );

And then I have a class BlogController that has a method -

   public ActionResult View(int id, string slug)
    {

       ... etc.
    }

I put a breakpoint in the first line of the View method but it's not getting hit at all. I checked with a route debugger for the format localhost/Blog/View/1/test and it matched my custom route. All I'm getting is a 404 while running this, I can't work out why the route won't post to the view method in my controller - any ideas?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2