0

Okay, so here's the deal. I've got controller called "Hotel" with view called "Index", where I'm trying to produce code allowing me to generate links in form of:

../Hotel?id=1

with ID passed as argument. To do so, I've tried using MapRoute:

@Html.RouteCollection.MapRoute("Hotel", "../{controller}/{id}", new { controller = "hotel" });

together with ActionLink:

@Html.ActionLink("More >>>", "", "Hotel", new { id = item.HotelId }, null)

But the outcome link goes like this:

Hotel/Index/1

Which leads to correct location, but burns visual consistency of all links at my website. I've tried RouteLink as well, but with no success.

Thanks in advance!

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

Do you want to make all links in the application use the standard querystring format for parameters named "id"? If so, removing the {id} from url and defaults object in the "Default" route should do that for you just fine.

If you want to limit it to the "Hotel" controller, you are on the right track w/ the custom route. First, make sure the custom route comes before the default route definition, and second, define it with nothing beyond the controller/action like:

routes.MapRoute(
            "HotelRoute", // Route name
            "Hotel/{action}/", // URL with parameters
            new { controller="Hotel", action = "Index" } // Parameter defaults
        );

Any params you pass in should then be appended to the query string as a name/value pair.

maf748
  • 768
  • 1
  • 4
  • 15