How to use key down event with Html text box helper in MVC4

10,162

Solution 1

You could do something like the following:

@Html.TextBox("txtbx1", "", new { onkeydown="MyFunction();" } )

Solution 2

Try it like this.

Call:

@Html.TextBoxFor(model => model.BoardSizeX, new { @onkeydown = "return Foo(event, $(this).val());"})

Function:

 function foo(event, currentValue) {
       console.log(event);
       console.log(currentValue);

       return true; 
}
Share:
10,162

Related videos on Youtube

Ell
Author by

Ell

Updated on June 04, 2022

Comments

  • Ell
    Ell almost 2 years

    How do you add a key down event with this text box?

    @Html.TextBox("txtbx1", "", new {...} )
    
  • Marlon
    Marlon over 7 years
    How can i access event parameters in this case?