문제

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