Here's my simple actionlink:

<span>@Html.ActionLink(trip.TripDescription, "Index", "Home", new { trip = trip.Trpp, year = trip.TripYear })</span>

Here is my route for that link:

routes.MapRoute(
                "Index",
                "{controller}/{action}/{trip}/{year}",
                new { controller = "Home", action = "Index", trip = "", year = "" }
            );

and here is what is being rendered:

http://localhost:31065/Home/Index?trip=Green&year=2013

I'd like for it to render this instead:

http://localhost:31065/Home/Index/Green/2013

both of those urls work, but cosmetically I'd prefer the latter.

what do I need to change to have the parameters go behind slashes instead of using the old school ? and &

TIA

有帮助吗?

解决方案

It looks as though your Index route is never being hit, probably due to some other route defined before. Always keep your most specific route definitions first and leave the default Controller/Action/Id to be defined last.

routes.MapRoute(
    "Index",
    "{controller}/{action}/{trip}/{year}",
    new { controller = "Home", action = "Index" }
);

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Default", action = "Index", id = UrlParameter.Optional }
);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top