Hi,
I need show alert message box after insert data and redirect on About page in asp.net mvc.
To show alert message in asp.net mvc after insert data using store procedure from MySQL database, I have write the code like as shown below.
The data is correctly registered in the database table.
But the alert message box after insert data don't show and the redirect not working.
What's wrong with it ?
thanks...
Index.cshtml
<script type="text/javascript">
$(function () {
var msg = '@ViewData["result"]';
if (msg == '1')
{
alert("User Details Inserted Successfully");
window.location.href = "@Url.Action("About", "Home")";
}
});
</script>
HomeController.cs
[HttpPost]
public ActionResult Index(PersonModel person)
{
string constr = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
using (MySqlConnection con =
new MySqlConnection(constr))
{
using (MySqlCommand command =
new MySqlCommand("SP_INS", con))
{
command.Parameters.AddWithValue("tLCL", person.LCL);
command.Parameters.AddWithValue("tContract", person.Contract);
command.Connection = con;
command.CommandType = CommandType.StoredProcedure;
con.Open();
ViewData["result"] = command.ExecuteNonQuery();
con.Close();
}
}
return View(person);
}