user2067567
user2067567

Reputation: 3803

Textbox ENTER to save the text to DB -- MVC

I have a text box and if user types something and Hit enter it should save it to the DB.

 @Html.TextArea("txtComments", new {@style = "width: 450px;",@placeholder = "Enter Comments here" })

Basically am looking for an event to fire on ENTER. and am implementing in RAZOR MVC.

i saw few ideas of keeping and other stuffs. But i thought this is the better place to post it.

Thanks

Upvotes: 1

Views: 1705

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

Basically am looking for an event to fire on ENTER

You could subscribe to the .keypress() event of the textarea and detect if Enter was pressed:

$(function() {
    $('#txtComments').keypress(function() {
        var code = e.keyCode ? e.keyCode : e.which;
        if(code == 13) { 
            // Enter was pressed => act accordingly
        }
    });
});

and am implementing in RAZOR MVC.

Razor is a view engine which runs on the server. You cannot detect key presses on the server. You will have to use client side scripting (javascript) as I have shown previously.

Upvotes: 3

Related Questions