Success Alert popup in mvc4 View without using jquery and AJAX

asp.net-mvc-4, jquery, razor

Solution

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`.

Problem

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 .

Original source