Pass a JS variable as Url.Action parameter

0

Hello, I would like to pass the JS variables parameter as a parameter, but it is not working, I would like to know the correct way to do this,

 <script>
    function check() {
         var teste1 = document.getElementById("lala");
         var teste2 = document.getElementById("lala2");
         @Url.Action("Teste", "Teste", teste1);
    }
 </script>
    
asked by anonymous 26.10.2016 / 17:50

1 answer

1

You can not mix javascript with Razor .

To do what you want, you would have to do something like this:

 <script>
    function check() {
         var teste1 = document.getElementById("lala");
         var teste2 = document.getElementById("lala2");
         var url = '@Url.Action("Teste", "Teste")/' + teste1;
         //Ou assim
         var url1 = '@Url.Action("Teste", "Teste")?teste=' + teste2;
    }
 </script>
    
26.10.2016 / 17:56