Search code examples
asp.net-mvcasp.net-mvc-5maproute

Creating an ActionLink and MapRoute that there is a constant name in it


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.


Solution

  • 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.