Pass a JS variable as the Url.Action parameter

Asked

Viewed 631 times

0

Hello, I would like to pass as parameter the variable JS, but it is not working, I would like to know the correct way to do this, I thank you already

 <script>
    function check() {
         var teste1 = document.getElementById("lala");
         var teste2 = document.getElementById("lala2");
         @Url.Action("Teste", "Teste", teste1);
    }
 </script>

1 answer

1

You can’t mix it up javascript with Razor.

To do what you wish, you’d 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>

Browser other questions tagged

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