views:

75

answers:

2

I feel a bit stupid asking this, but I just want to know how I can have a html button call a server site action on my controller.

For example lets say I have a Text Area and a submit button. The idea would be to click the submit button and the text in the text area would get submitted to the Database. Very simple stuff.

Thank you for the help!

A: 

In the view's HTML, the text area and submit button would be part of a form, and that form's action attribute would point to '' and you'd put a part into the same controller that generated that view that checks for POST data. If there's POST data, you'd write it to the database.

The form would look something like this:

<form action='' method='post'>
    <textarea name="text"></textarea>
    <input type="submit" value="Submit"/>
</form>

In the POST, you'll see a variable with a key that matches the name attribute of the textarea (in this case, text). You can read it from there.

If you like, you can also change the action attribute on the form to a URL, in which case you'd write the part that checks the POST data in a controller that that URL points to.

Michael Louis Thaler
Thanks for the comment. But, how would I define the server side function that gets the textarea data?
hanesjw
+4  A: 
curtisk
thank you for the comment. So far that seems to have worked, the only problem I am having now is that after it returns from the 'Hello' action it messes up my URL. do you know how do I return a View of the same Controller/Action/ID I currently have in the url?
hanesjw
I updated answer to address this question...
curtisk
Any luck on the updated answer?
curtisk