[RESOLVED]How to put the Alert Message in Mvc Technology?

Hi Friends,

            I have created One Small example in mvc.In  that at every action ,I need to show the alert message when i inset successfully and Update , And Delete Respectively .

How to do this things in coding ,Provide me example Coding as well .

Thanks in Advance ,

-Ernesto Karthik


ViewBag / Model

In the javascript, put an alert with the message

Hi Karthik,

Do it like:

//In controller action:

    TempData["AlertMessage"] = "my alert message";
    return RedirectToAction("SomeAction");

//In View

    var message = TempData["AlertMessage"] ?? string.Empty;

<script type="text/javascript">
    var message = '@message';

In web pages I typically don’t show alerts as they are not customizable and stylish. Recently I am using a small javascript library called toastr to show the messages. Please take a look at this demo


Hi Karthik Che,

Thanks for your post.

Please refer to the following code snippet:

public ActionResult demo7()
// ViewBag.Scripts = "<script>alert('hello')</script>"; return View(); }

in view:


Hope this can be helpful.

Best Regards,


Hi Che,

If you show  alert message, use jQuery alert("Message"), better you can use response format like Success label or failure label.



Leave a Reply