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;
}
Related videos on Youtube
Author by
Ell
Updated on June 04, 2022Comments
-
Ell almost 2 years
How do you add a key down event with this text box?
@Html.TextBox("txtbx1", "", new {...} )
-
Marlon over 7 yearsHow can i access event parameters in this case?