I am using MVC 4 and ASP.NET to ask a user on the Home page to enter text in textboxes. After the user clicks the submit button, a MySQL database should be updated. The problem I am having is linking the submit button to the controller with the code to save the data submitted to the already set up database running on a server.
The last part of Index.aspx View is as follows:
<asp:Button ID="submit_database" runat="server" Text="Add to Database" ToolTip="Submit" OnClick="location.href='/controller/HomeController/submit_database_Click1'"/>
The code in HomeController.cs :
public void submit_database_Click1(Object sender, EventArgs e)
{
UserModel userModel = new UserModel(Request["first_name_text_box"],
Request["middle_name_text_box"],
Request["last_name_text_box"],
Request["city_text_box"],
Request["state_text_box"]);
string constring = "server=#;uid=table;pwd=Password;database=databaseName;";
MySqlConnection conn = new MySqlConnection(constring);
conn.Open();
MySqlCommand comm = conn.CreateCommand();
comm.CommandText = "INSERT INTO user(first_name, middle_name) VALUES (@firstName, @middleName)";
comm.Parameters.AddWithValue("@firstName", Request["first_name_text_box"]);
comm.Parameters.AddWithValue("@middleName", Request["middle_name_text_box"]);
comm.ExecuteNonQuery();
conn.Close();
How exactly do I format the code in Index.aspx to submit the data from Index.aspx to the server?