Creating an ActionLink and MapRoute that there is

2019-08-31 16:40发布

问题:

In my Asp.net MVC 5 (C#) project I want to create some links by @Html.ActionLink or every you know is better like:

/Tags/Linq

/Tags/SqlServer

/Tags/MVC

That Tags is constant name and after that in the URL is tag name.For example like ScottGu's Blog

In addition I want to pass a parameter such as Id but I don't want to show in the URL.

How can I do it?

And how should I write a suitable MapRoute for it?

Please help me.

回答1:

For example (don't forget to write it before default route):

routes.MapRoute(
     "Tags",
     "tags/{tagTerm}",
     new { controller = "Tags", action = "SearchTagResults" }
);

In addition (passing Id) use POST not GET.