I have create web app in MVS 3
but failed to display alert message after data insert into database
Controller code:
[HttpPost]
public ActionResult QuestionBank(QuestionBank questionbank)
{
if (ModelState.IsValid)
{
dbEntities.QuestionBanks.AddObject(questionbank);
dbEntities.SaveChanges();
//questionbank.SendEnquiryEmail(questionbank);
ViewData["Message"] = "Data inserted";
return RedirectToAction("QuestionBank");
}
return View(questionbank);
}
Used ViewData[“Message”] = “Data inserted”; which is not displayed message 🙁
whats going wrong or i placed it somewhere else?
OR ELSE I MAY HAVE THIS CODE
<script type="text/javascript">
//i'm using jquery ready event which will call the javascript chunk after the page has completed loading
$(document).ready(function () {
//assuming that your variable name from the code behind is bInsertSuccess
var bSuccess = "<%= myvar %>";
if (bSuccess) {
alert("Successfully Inserted");
}
});
</script>
but i dont know where i declare that variable myvar which checks insertion plz help
On your .chsthml page:
in your action:
Edit: Apply conditional check in script:
In view:
ViewData["Message"]would result in same thing here.