0

I have this code

var txt;

function change(){
    txt = "@Utils.GeneratePass()";      
    document.getElementById("password_field").value = txt;   
}

function changeToHash(txt){
      alert(window.txt);
      var password = "@Utils.Hash(txt)";
      document.getElementById("password_field").value = password;        
}

In method @Utils.Hash i need pass one string, and i want put the value of txt. But i got the error "The name 'txt' does not exist in the current context.

jarmod
  • 71,565
  • 16
  • 115
  • 122
Marco
  • 21
  • 4

1 Answers1

0

You cannot pass js variable to C# code,you can try to pass @Utils.GeneratePass() to @Utils.Hash():

var txt;

function change(){
    txt = "@Utils.GeneratePass()";      
    document.getElementById("password_field").value = txt;   
}

function changeToHash(txt){
      alert(window.txt);
      var password = "@Utils.Hash(Utils.GeneratePass())";
      document.getElementById("password_field").value = password;        
}
Yiyi You
  • 16,875
  • 1
  • 10
  • 22