Reputation: 849
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 .
Upvotes: 5
Views: 24430
Reputation: 26940
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
.
Upvotes: 19