asp.net mvc3 应用程序的状态通知系统

发布于 2024-12-04 23:07:58 字数 720 浏览 1 评论 0 原文

我只是想知道如何为 ASP.NET MVC3 应用程序实现通知系统,就像基本上当用户登录系统并成功登录页面时显示消息(如果不是错误消息)一样。

我有一些方法可以解决上述问题,将属性值保留在视图模型上,但不知道当我们将通知从一个控制器传递到另一个控制器或从一个操作传递到另一个操作时如何实现。

就像当我们登录系统时,从帐户控制器到家庭控制器的登录成功消息,并在主页上显示通知消息用户登录成功。

如果您可以提供,这将非常方便我了解代码示例或解决上述问题的一些最佳方法。

Thnaks

P.S

这是我正在尝试使用的一些代码片段

 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 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");
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别在捏我脸啦 2024-12-11 23:07:58

我喜欢使用 purr jQuery 插件

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

如果我想显示状态消息,我将其添加到 TempData。
在我的页面底部,我有一个辅助方法,如果它找到 TempData["StatusMessage"],它会调用 purr 来显示它。

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.

天气好吗我好吗 2024-12-11 23:07:58

您还可以尝试 MvcNotification。在 GitHub 中,您可以找到一个示例 ASP.NET MVC 项目,该项目显示了执行通知的多种方法,包括 AJAX 场景。

MvcNotification 是一个示例应用程序,它展示了不同的方式
在 ASP.NET MVC 控制器操作中显示通知
不引人注目的方式。

我目前正在使用它,它做得很好...只需注意何时使用正确的方法调用,将 truefalse 传递给参数 ShowAfterRedirect< /代码>。根据具体情况,代码使用控制器的 TempData 或 ViewData 属性。有关其用法的更多信息此处

// 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);

作者的博客文章包含实现细节:http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/


最近有toastr

简单的 JavaScript Toast 通知。
toastr 是一个用于非阻塞通知的 Javascript 库。 jQuery
是必须的。目标是创建一个简单的核心库
定制和扩展。

这么好的 JS 库!

您可以在此处查看演示页面。

代码可在 GitHub 获取。

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.

吐个泡泡 2024-12-11 23:07:58

不知道有多少人仍在寻找一种方法来做到这一点。我在当前的应用程序中实现了一种非常简单的方法来执行此操作,并在我的博客上编写了有关如何执行此操作的指南。我的方法实际上是我看到的其他 3 种方法的组合(我觉得对我来说有点太复杂了,因为我刚刚开始使用 MVC)。无论如何,我希望这可以帮助任何寻找一种非常简单的方法来做到这一点的人:

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文