User route does not find controller action

For some reason, my application does not properly direct my controller method. I have such a link on my web page -

<%= 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 BlogController class that has a method -

   public ActionResult View(int id, string slug)
    {

       ... etc.
    }

I set a breakpoint in the first line of the View method, but I don't get any hit. I checked with the route debugger for the localhost / Blog / View / 1 / test format and it matched my custom route. All I get is 404 while running, I can’t understand why the route will not send to the view method in my controller - any ideas?

+3
source share
2 answers

(, debugger post)

404, , .

0

, , RouteLink , , area="" routeValues ​​( ). , , area="..." RouteLink .

, RouteLink Area, , , .

0

Source: https://habr.com/ru/post/1748217/


All Articles