I've created a MVC application. User has to register and once it is completed, I'm redirecting him to "thank you" page. However I would like just to show user a pop-up with this message. How can I achieve this?
My code:
[HttpPost]
public ActionResult Enquiry(Enquiry enquiry)
{
if (ModelState.IsValid)
{
dbEntities.Enquiries.AddObject(enquiry);
dbEntities.SaveChanges();
enquiry.SendEnquiryEmail(enquiry);
return RedirectToAction("Thankyou");
}
return View(enquiry);
}
//redirect to thankyou page
public ActionResult Thankyou()
{
return View();
}
To ensure your 'alert' in your view only shows up when you intend (a redirect from your ThankYou method) and not when somebody accidentally navigates to your 'ThankYou' view
//redirect to thankyou page
public ActionResult Thankyou()
{
TempData["alertMessage"] = "Whatever you want to alert the user with";
return View();
}
Then in your "ThankYou" view, this:
if(null != TempData["alertMessage"])
{
<script type="text/javascript">
alert("@TempData[alertMessage]");
</script>
}
This will write out the script as you normally would for any JavaScript. Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With