开发者

Status Notification System for asp.net mvc3 Application

I just wonder how to implement notification system for asp.net mvc3 application like basically when user logged in to t开发者_开发问答he 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");
 }


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.


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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜