ASP.NET MVC中,如何将局部视图的Flash消息转换为长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计545个文字,预计阅读时间需要3分钟。
使用FlashHelper向用户显示Flash消息时,若需要显示部分视图而非默认的Flash消息,可以通过以下方式实现:
javascriptFlash.Success(部分视图消息, FlashMessagePartial);
或者,使用:
javascriptFlash.Success(自定义消息, FlashMessage);
这样就可以根据需要显示特定的视图或消息了。
我正在使用FlashHelper向用户显示flash消息,我需要显示部分视图而不是默认的flash消息.我怎么能这样做或者是否可能?我需要一个这样的帮手:
Flash.Success( “_ FlashMessagePartial”,型号)
或者你建议有图书馆吗?
你不能这样使用它.如果我理解正确,您希望向用户显示类似通知的内容,并且您不希望刷新页面.正确的答案是你可以做到,但这是不正确的.您的代码看起来一团糟,您将有一个隐藏的通知字段,依此类推.这取决于你想要完成什么.例如:我在我的布局中使用全局通知,我的剪辑看起来像这样
在布局的顶部就在之前
我放置一个if语句来检查TempData中是否存在错误消息
@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重量轻,使用方便
希望这个答案能够准确地解释您的需求.
本文共计545个文字,预计阅读时间需要3分钟。
使用FlashHelper向用户显示Flash消息时,若需要显示部分视图而非默认的Flash消息,可以通过以下方式实现:
javascriptFlash.Success(部分视图消息, FlashMessagePartial);
或者,使用:
javascriptFlash.Success(自定义消息, FlashMessage);
这样就可以根据需要显示特定的视图或消息了。
我正在使用FlashHelper向用户显示flash消息,我需要显示部分视图而不是默认的flash消息.我怎么能这样做或者是否可能?我需要一个这样的帮手:
Flash.Success( “_ FlashMessagePartial”,型号)
或者你建议有图书馆吗?
你不能这样使用它.如果我理解正确,您希望向用户显示类似通知的内容,并且您不希望刷新页面.正确的答案是你可以做到,但这是不正确的.您的代码看起来一团糟,您将有一个隐藏的通知字段,依此类推.这取决于你想要完成什么.例如:我在我的布局中使用全局通知,我的剪辑看起来像这样
在布局的顶部就在之前
我放置一个if语句来检查TempData中是否存在错误消息
@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重量轻,使用方便
希望这个答案能够准确地解释您的需求.

