How to change running route?

Asked

Viewed 182 times

1

Use MVC5 and Visual Studio 2013. I created this route: Home/PaginaBase. This route calls a new page, called PaginaBase, which has a header and footer similar to Index. This footer creates a Menu. When I select an item from that menu, it calls me to PaginaBase, mounting the URL like this:

http://www.localhost:58686/Home/Paginabase/6/3.

So far, ok. When I will select another item (I am still inside the PaginaBase), it keeps the same URL in the call and adds again Home/PaginaBase/8/3, there is a route missing. How do I solve this?

Below my jquery function

function MontaMenuInferior() {

    var str = "";
    $.ajax({
        url: '/Home/MontaMenuInferior',
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        type: "POST",
        success: function (data) {

            $(data.resultado).each(function () {

                str = str + '<ul class="grid_4">' +
                                    '<li>' + this.SubCategoria + '</li>';


                $(this.subconsulta).each(function () {

                    if (this.Id_SubCategoria2 != null) 

                        str = str + '<li><a href="Home/PaginaBase/' + this.Id_SubCategoria2 + '/3" title="">' + this.SubCategoria2 + '</a></li>';
                        //str = str + '<li><a href="@Url.RouteUrl(PaginaBase"',new{ Parametro : this.Id_SubCategoria2, tipo : '3'} + ")">this.SubCategoria2 + '</a>'
                    else
                        str = str + '<li><a href="#' + this.SubCategoria2 + '" title="">' + this.SubCategoria2 + '</a></li>';

                });

                str = str + '</ul>';

                $('#menufooter').append(str);

                str = "";

            });
        },
        error: function (error) {

        }
    });
}
  • 2

    Why these numbers at the end of your Urls? Wouldn’t it be better to just use the proper view names?

  • What do you mean? These numbers are parameters I step to call certain html. They are bd ID’s.

  • The problem of duplication, is that there was a bar missing in the link call, type: /Home/Paginabase... and not Home/Paginabase.... That I already solved, now called my attention in relation to the name suggested by Tiago.

1 answer

1

You are using relative Urls on your links. If you are on /Home/PaginaBase/6/3 (i.e. this is your path) and you click a link to Home/PaginaBase/8/3 your new path will be /Home/PaginaBase/6/3/Home/PaginaBase/8/3.

If you use relative Urls it will replace your path instead of concatenating to it: /Home/PaginaBase/8/3 (note the / at first).

P.S. Dei that answer in your question on SOEN before reading his comment saying that he had already found the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.