简体   繁体   中英

.net HTML.RouteLink passes parameter as key-value pair not rout

So in my RouteConfig I have a route that looks like this:

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

And I am making a link like this:

@Html.RouteLink("Thing", new { controller = "Modules", action = "View", GUID = "27ACBB7C-075A-49BD-9B43-000EAE3E6B6F" })

I want it to create the following link:

<a href = ".../Modules/View/27ACBB7C-075A-49BD-9B43-000EAE3E6B6F">Thing</a>

But instead I'm getting:

<a href = ".../Modules/View?GUID=27ACBB7C-075A-49BD-9B43-000EAE3E6B6F">Thing</a>

How do I get RouteLink to put the parameter as a path rather than a key-value pair?

(This seems so obvious I'm sure someone's going to tell me this is a duplicate question but I've searched for the question with every keyword I know so I'll be happy to get the answer from an existing question if it already exists.)

This usually happens when the method inside the controller has the wrong parameter name.

inside the Modules controller, the View method should be defined as:

View(Guid GUID)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM