– Hide parameters in URL with routes and mvc 5


I have a route like this:

    name: "RotaConteudo",
    url: "Conteudo/{name}/{Parametro}/{tipo}",
    defaults: new { controller = "Conteudo", action = "Conteudo", name = "", Parametro = "", tipo = "" }

When you go up the page, my url looks like this.


The 3/3 are the respective parameters passed in the route. Is there a way to hide them in the URL?

I have a foreach (in the home) that assembles my URL, like this:

foreach (var item3 in item2.subconsulta2)
    if (item3.Id_SubCategoria2 != null)
        str = str + "<li><a href=\"/Conteudo/" + item3.Id_SubCategoria2 + "/3/" + retira_acentos(item3.SubCategoria2).ToLower().Replace(" ", "-") + "\" title=\"\">" + item3.SubCategoria2 + "</a></li>";
        str = str + "<li><a>" + item3.SubCategoria2 + "</a></li>";

It sends these parameters to a method I have in a controller and it goes to the database and gets the HTML corresponding to that parameter. If I could pass the parameter, other than the URL, I would redo the Route, to display just the name, as the HTML will be shown by the parameter passed in another way.


To send data to the server other than the URL, the only way I know of is via POST .

Now the problem is how to make a POST from a link… the way I know is you create a form on the page and submit it using javascript on the click of the link, and to hide some of the parameters, just put input s inside this form and set their value before submitting via script.

Functional example: using jquery


    name: "RotaConteudo",
    url: "Home/{name}",
    defaults: new { controller = "Home", action = "Conteudo", name = "" }


function linkPost(e, params) {

    var $form = $("<form action='' method='POST'></form>");

    for (var key in params)
        $("<input type='hidden'/>").attr("name", key).val(params[key]).appendTo($form);

        .attr('action', $(this).attr('href'))

    return false;


<a href="@Url.Action("Conteudo", new { name = "agt" })"
   onclick="javascript:return linkPost.apply(this, [event, { parametro: 3, tipo: 3}]);"
>agt 3, 3</a>
Scroll to Top