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?

kloarubeek
  • 2,706
  • 20
  • 24
thejuki
  • 1,351
  • 2
  • 13
  • 16
  • 1
    This is web forms code, not MVC –  Sep 18 '14 at 23:34
  • Is there a way to make it compatible with MVC? – thejuki Sep 18 '14 at 23:37
  • Why would you want to? But [the answers here](http://stackoverflow.com/questions/2203411/combine-asp-net-mvc-with-webforms) might help –  Sep 18 '14 at 23:46
  • This also has nothing to do with [tag:asp-classic], please [learn the difference](http://www.beansoftware.com/ASP.NET-Tutorials/Classic-ASP-vs-ASP.NET.aspx). – Paul Sep 19 '14 at 09:13

0 Answers0