user3045352
user3045352

Reputation: 61

setup routing for homepage

I have two routes in my RouteConfig.cs file. I'm not able to run both at the same time so the one on top gets executed:

routes.MapRoute(
        "ScNewsList",
        "{controller}/{id}/{title}",
        new { controller = "news", action = "SpecialCollectionList", id = UrlParameter.Optional, title = UrlParameter.Optional }
        );

        routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "home", action = "Index", id = UrlParameter.Optional }
        );

How do i gets rules running for both:

http://localhost:53098/news/312/SpecialCollectionList
http://localhost:53098/

The second one should mapped to homepage?

Upvotes: 1

Views: 43

Answers (2)

Matt Tabor
Matt Tabor

Reputation: 1053

you can do it this way by manually setting the route to news

routes.MapRoute(
    "ScNewsList",
    "news/{id}/{title}",
    new { controller = "news", action = "SpecialCollectionList", id =     UrlParameter.Optional, title = UrlParameter.Optional }
    );

    routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}/{id}",
      defaults: new { controller = "home", action = "Index", id = UrlParameter.Optional }
    );

Upvotes: 0

GvM
GvM

Reputation: 1733

If you're meaning to always have your ScNewsList route run against the news controller, then you can update the url to be "news/{id}/{title}".

That way your Default route will be a catch all outside of the ScNewsList route.

Upvotes: 1

Related Questions