How to use message box in MVC controller?
@Reynolds
Your answer is perfect.
In Razor, the following line can be replaced
alert("@TempData[alertMessage]");
by the following
alert('@TempData["alertMessage"]');
PS. Notice the quotes
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!