asp.net-mvc – 作为局部视图的Mvc flash消息
发布时间:2020-12-16 09:20:12 所属栏目:asp.Net 来源:网络整理
导读:我正在使用FlashHelper向用户显示flash消息,我需要显示部分视图而不是默认的flash消息.我怎么能这样做或者是否可能? 我需要一个这样的帮手: Flash.Success( “_ FlashMessagePartial”,型号) 或者你建议有图书馆吗? 解决方法 你不能这样使用它.如果我理解
我正在使用FlashHelper向用户显示flash消息,我需要显示部分视图而不是默认的flash消息.我怎么能这样做或者是否可能?
我需要一个这样的帮手: Flash.Success( “_ FlashMessagePartial”,型号) 或者你建议有图书馆吗? 解决方法
你不能这样使用它.如果我理解正确,您希望向用户显示类似通知的内容,并且您不希望刷新页面.正确的答案是你可以做到,但这是不正确的.您的代码看起来一团糟,您将有一个隐藏的通知字段,依此类推.这取决于你想要完成什么.例如:
我在我的布局中使用全局通知,我的剪辑看起来像这样 在布局的顶部就在之前 @if(TempData["error"]) { // here you can visualize it well styled by some template for example <div class="notification-error">@TempData[error]</div> } @if(TempData["success"]) { // here you can visualize it well styled by some template for example <div class="notification-error">@TempData[error]</div> } Then in your controller if you have something to say to the user you can just do what you are doing like: public ActionResult SomeAction(MyModel model) { if(something is not valid) { this.TempData["error"] user error return this.View(model); } } That case was if you need some server validation and proper message to the user. After that option you have to set a script on your layout that removes the error and success notifications if they exist on the page loads. 另一个选项是,如果您需要在客户端进行一些模型状态验证,您可以查看由viewmodel属性驱动的js-unobtrusive验证,它会让您在进入服务器之前自动检查客户端. 第三个选项是如果你需要一些其他通知,你可以使用名为toastr的JS库. Examples library url重量轻,使用方便 希望这个答案能够准确地解释您的需求. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – Ajax Control Toolkit ModalPopupExtender无法在
- asp.net – 将服务器端事件添加到扩展程序控件
- 谈谈基于SQL Server 的Exception Handling
- ASP.Net WebApi身份验证和安全性
- [asp.net mvc 奇淫巧技] 05 - 扩展ScriptBundle,支持混淆加
- 将asp.net值传递给javascript块
- 有没有办法检查是否定义了VBScript函数?
- asp.net – Web Deploy和Parameters.xml:如何在多个项目之
- asp.net-mvc – window.location.href发送多个参数asp.net
- asp.net-mvc-4 – ASP.NET MVC 4 Razor视图无法识别Dropdow
推荐文章
站长推荐
- Cassini上的ASP.NET MVC:如何强制“内容”目录返
- asp.net-web-api – Web API ODataResult始终序列
- asp.net-mvc-4 – 使用导航路由的ASP.NET,Twitte
- asp.net – IIS 7.5上的ReportViewer 10.0无法呈
- asp.net-mvc – 用于MVC 3的Castle Windsor依赖关
- Asp.net mvc 知多少(七)
- asp.net-mvc – 在ASP.NET MVC应用程序中实现细粒
- asp.net – 关系从一对多变为多对多需要更新list
- asp.net – 绕过表单身份验证自动重定向到登录,如
- 将自定义ValueProviderFactories添加到ASP.NET M
热点阅读