How to put hash to an asp.net mvc url?

2

I do not really know how to explain this topic, what happens is that made my application in mvc and asp .net, then every time I enter my menu on my website and access to a page my url is this: localhost: 1523 / en / quienessomos

Menu that I use in asp.net

  <ul class="dropdown-menu">
    <li><a  href="@Url.Action("quienessomos", "es")">Quiénes Somos</a>
    </li>
  </ul>

and my page appears of who we are, until there is good because it renders the views.

But I am adding a theme that gave me the frontend, the theme was made in html, and it is necessary that the url be in this way so that it renders well to the page and its theme works, it seems that it looks for a .hash: localhost: 8090 / en / # quienessomos

the menu you use in html:

      <ul class="dropdown-menu">
        <li><a href="#quienes-somos">Quiénes Somos</a></li>
      </ul>

Well my problem is that the animation that makes this script that you attach does not work because of this hash problem, please I need some idea thanks.

he uses this script:

$('document').ready(function(){
    // $('.ToolTip').tooltip();
    // $('.popOver').popover();

    $('[data-toggle="tooltip"]').tooltip();
    $('[data-toggle="popover"]').popover();
    
    // new WOW().init();



  //CARRUSEL
  // $('.carousel').carousel({
  //   interval: 2000
  // });

  $('#carousel-home').carousel({
    pause: "false"
  });
});



// $("#bg-anima").animate({width: '100%'}, 800);
// $("#bg-anima").animate({left: '100%'}, 600);



// AJAX
var default_content="";
var urlWeb = window.location.hash;

$(document).ready(function(){
    if(!urlWeb){
        // $("#pageContent").load('pages/home.html');
    }else{
        checkURL();
        //filling in the default content
        // default_content = $('#pageContent').html();     //llena la variable default_content con el contenido actual del div #pageContent
        setInterval("checkURL()",50);
    }
});

// var activo="";

$('#navbar-collapse-sup .dropdown-menu li a').click(function (e){
    checkURL(this.hash);

    $("ul li").removeAttr('class');
    $(this).parent().addClass("active");

    $(".navbar-collapse").animate({height: '1'},300,
        function(){
            $(".navbar-collapse").removeClass("in");
        }
    );
    // $("#bg-anima").animate({left: '100%'}, 600);
});

var lasturl="";

function checkURL(hash){
    if(!hash)
        hash = window.location.hash;    //llena la variable hash con el hash de la url actual
    if(hash != lasturl)
    {
        lasturl=hash;
        // FIX - if we've used the history buttons to return to the homepage,
        // fill the pageContent with the default_content
        if(hash=="")
            $('#pageContent').html(default_content);
        else
            $(".navbar").animate({left: '0'},600);
            $("#contenedor-pagina").animate({left: '300px'},600);
            $("#bg-anima").animate({width: '100%'}, 600,
                function(){
                    loadPage(hash);
                }
            );
    }
}

function loadPage(url){
    url = url.replace('#','');
    // $('#loading').css('visibility','visible');
    $.ajax({
        type: "POST",
        // url: "load_page.php",
        url: "pages/" + url + ".html",
        // data: 'page=' + url,
        dataType: "html",
        error: function(){
            $('#pageContent').html( "<p>Page Not Found!!</p>" );
        },
        beforeSend: function(){
            $('#pageContent').html( '<img class="loading" src="img/web/loading.gif" alt="loading">' );
        },
        complete: function(){
            // jContent.html( "<p>AJAX - complete()</p>" );
        },
        success: function( msg ){
            if(parseInt(msg)!=0)
            {
                $('#bg-anima').animate({left: '100%'}, 400);
                $('#pageContent').html(msg);
                // $('#loading').css('visibility','hidden');
                $('#bg-anima').animate({width: '0%'}, 0);
                $('#bg-anima').animate({left: '0%'}, 0);

                // $('#menu-extra').addClass('hidden-sm hidden-md hidden-lg');
                $('#menu-extra').css('display','none');
                $('#menu-extra-nav').addClass('visible-sm visible-md visible-lg');
                $('#redes').addClass('visible-sm visible-md visible-lg');

                $('#carousel-nav').css('display','none');

                $("footer").load('pages/footer.html');
            }
            // $(".container").perfectScrollbar();
        }
    });
}
    
asked by elizabeth 22.04.2016 в 01:12
source

1 answer

1

I understand that the link is captured by the jquery click event until you reach loadPage()

The issue is that there you remove the # but be arming incorrectly the url

First I do not know why you put pages and then so that the .html is a mvc action you just have to define the controller and the action you are going to invoke.

then in the link you could use

<a href="#es/quienes-somos">Quiénes Somos</a>

and in the ajax invocation you define direct url

$.ajax({
    type: "POST",
    url: url,
    dataType: "html",

but it works maybe you should unite the root of the site or http://localhost:1523 + url

    
answered by 22.04.2016 в 07:48