I had my submit form working from my razor file to a controller, then from the controller to my remote database. but now i don't even think the controller class is being called.
Here is my view:
@model InputEvent
@using (Html.BeginForm("Save", "Portal/Controllers/MyEvent"))
{
<md-input-container class="md-block" flex-gt-xs="">
<label>Title</label>
@Html.TextBoxFor(m => m.title)
</md-input-container>
<md-input-container class="md-block">
<label>Address</label>
@Html.TextBoxFor(m => m.address)
</md-input-container>
<md-button class="md-raised">
<input type="submit" value="Save" />
</md-button>
}
with my model:
public class InputEvent
{
public string title;
public string address;
}
And my controller with the database connection:
namespace Portal.Controllers
{
public class MyEventController : Controller
{
[HttpPost]
public ActionResult Save(InputEvent y)
{
MySqlConnection conn = new MySqlConnection("mydbstring");
string myTitle = y.title;
string myAddress = y.address;
conn.Open();
MySql.Data.MySqlClient.MySqlCommand comm = conn.CreateCommand();
comm.CommandText = "INSERT INTO event(title, address) VALUES(@title, @address)";
//comm.Parameters.AddWithValue("@title", myTitle);
//comm.Parameters.AddWithValue("@address", myAddress);
comm.Parameters.AddWithValue("@title", "test_title");
comm.Parameters.AddWithValue("@address", "test_address");
comm.ExecuteNonQuery();
conn.Close();
return View();
}
}
}
Am i not calling my controller correctly? or is my sql command invalid?
EDIT: I just checked my database again over an hour later, and i have multiple rows with "test_title" and "test_address" in there. i guess my code works, but it is VERY delayed. This might not be the best place to ask, but does anyone have any idea why it could be so delayed inserting into the DB?
Html.BeginForm("Save", "MyEvent")instead of the explicit controller path. What does the browser show in the dev console when submitting the form?"Portal/Controllers/MyEvent"with the actual name of the controller - i.e."MyEvent"