简体   繁体   中英

How to Update Textbox.Text on Button Press

Apologies for what is undoubtedly a newb question, but I have been unable to find a specific answer.

I have c#-integrated ASP.net Core project, with an SQL backend. I can run queries for individual entries just fine, but my problem is a far more mundane one.

I have a textbox, which I want to reload the page when the Enter key is pressed which the Text value appended to it. Eg '~/GetPerson?name=' with the text the user's entered placed at the end.

This seems simple enough, and I'm probably missing the obvious, but I remain befuddled.

do you want this?

$("#textBox").on("keyup", function(e){
    e.preventDefault();
    if(e.keyCode===13){
       //do call server or something
    }
}

You can do something like this

$("#textBox").on("keyup", function(e){
    e.preventDefault();
    if(e.keyCode===13){
       var name = (this).val();
       window.location.href = '@Url.Action("GetPerson", "YourController")?name=' + name;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM