我只是想知道如何为 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");
}
发布评论
评论(3)
我喜欢使用 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.
您还可以尝试 MvcNotification。在 GitHub 中,您可以找到一个示例 ASP.NET MVC 项目,该项目显示了执行通知的多种方法,包括 AJAX 场景。
我目前正在使用它,它做得很好...只需注意何时使用正确的方法调用,将
true
或false
传递给参数ShowAfterRedirect< /代码>。根据具体情况,代码使用控制器的 TempData 或 ViewData 属性。有关其用法的更多信息此处。
作者的博客文章包含实现细节:http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/
最近有toastr。
这么好的 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.
I'm currently using it and it does a good job... just pay attention when to use the right method call passing
true
orfalse
to parameterShowAfterRedirect
. Depending on circumstances the code uses controller's TempData or ViewData properties. More about their usage here.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.
Such a nice JS library!
You can check a demo page here.
Code available at GitHub.
不知道有多少人仍在寻找一种方法来做到这一点。我在当前的应用程序中实现了一种非常简单的方法来执行此操作,并在我的博客上编写了有关如何执行此操作的指南。我的方法实际上是我看到的其他 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/