Ell
Ell

Reputation: 83

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

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

@Html.TextBox("txtbx1", "", new {...} )

Upvotes: 4

Views: 11379

Answers (2)

Andréw
Andréw

Reputation: 106

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; 
}

Upvotes: 1

Jack
Jack

Reputation: 9242

You could do something like the following:

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

Upvotes: 6

Related Questions