0

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?

4
  • 1
    This is web forms code, not MVC Commented Sep 18, 2014 at 23:34
  • Is there a way to make it compatible with MVC? Commented Sep 18, 2014 at 23:37
  • Why would you want to? But the answers here might help Commented Sep 18, 2014 at 23:46
  • This also has nothing to do with asp-classic, please learn the difference. Commented Sep 19, 2014 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.