8

I just wonder how to implement notification system for asp.net mvc3 application like basically when user logged in to the system with successfully login page shows message if not error message.

i have some approach with the above problem keeping property value on viewmodel but don't know how to achieve when we passing notification from one controller to another controller or from one action to another action.

like when we log in to system login succeeded message from account controller to home controller and shows notification message on home page user login succeeded.

please it'll really convenient me to understand if you could provide code sample or some best approach with the above issue.

Thnaks

P.S

Here is the some code snippet that i'm trying with

 public ActionResult Register(UserRegistrationViewModel registrationModel)
 {
   //some logic and when end of the code set the error message and
   //redirect to separate action and after new action can read the message and show
      if(success)  
         return RedirectToAction("Index","Home"); 
      else
         return RedirectToAction("Logon");
 }

3 Answers 3

10

I like to use the purr jQuery plugin

http://code.google.com/p/jquery-purr/

If I want to show a status message, I add it to TempData. At the bottom of my pages I have a helper method which if it finds a TempData["StatusMessage"] it calls purr to display it.

7
  • Hi Adam thanks for the reply but this is not what i'm looking for i have just update the my question.
    – Gayan
    Sep 15, 2011 at 19:34
  • what I posted would do what you mention as how I understand your question. Sep 16, 2011 at 0:59
  • TempData is designed for passing information between your requests (and hence action methods) without having to specify separate parameters. Sep 16, 2011 at 2:41
  • but when i try to assign message in to TempData["message"] in Register action and try to get it from Login Action TempData["message"] giving empty value.
    – Gayan
    Sep 16, 2011 at 5:47
  • 1
    OK TempData is the awesomest solution for my need i wrote a appropriate code for the above need thanks for the tip Adam cheerzz..
    – Gayan
    Sep 16, 2011 at 12:24
4

You could also try MvcNotification. At GitHub you find a sample ASP.NET MVC project that shows multiple ways for doing notifications, including AJAX scenario's.

MvcNotification is a sample application that shows different ways for displaying notifications from ASP.NET MVC controller actions in an unobtrusive way.

I'm currently using it and it does a good job... just pay attention when to use the right method call passing true or false to parameter ShowAfterRedirect. Depending on circumstances the code uses controller's TempData or ViewData properties. More about their usage here.

// If you want to display a message after a redirect, for example:
// call ShowMessage with true just before return RedirectToAction("Index");
this.ShowMessage(MessageType.Success, "YourMessage", true);

Author's blog post with implementation details: http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/


More recently there's toastr.

Simple javascript toast notifications. toastr is a Javascript library for non-blocking notifications. jQuery is required. The goal is to create a simple core library that can be customized and extended.

Such a nice JS library!

You can check a demo page here.

Code available at GitHub.

0
1

Not sure how many people are still looking for a way to do this. I implemented a very simple approach to doing this in my current application and wrote up a guide on my blog on how to do it. My method is actually a combination of 3 others that I saw (and felt were a little too complex for me right now since I'm just getting started with MVC). Anyway, I hope this helps anyone looking for a really simple way to do this:

http://www.nfynite.com/2012/04/07/simple-mvc-3-notifications-with-razor-and-jquery/

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.