Is it possible to get an alert popup on return to same view after success in mvc4 without using ajax begin form?
I'm trying to submit a form and on success want to show a alert box without using ajax and jquery .
When you submit form, I think then you are redirecting, am i right? So you can use TempData
for this purpose:
In controller action:
if(success)
{
TempData["AlertMessage"] = "my alert message";
return RedirectToAction("SomeAction");
}
The view which SomeAction
action returns (or in layout view):
@{
var message = TempData["AlertMessage"] ?? string.Empty;
}
<script type="text/javascript">
var message = '@message';
if(message)
alert(message);
</script>
NOTE: If you are not redirecting, but returning view, just use ViewBag
instead of TempData
.
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