Mvc 将消息闪烁为部分视图



>我正在使用FlashHelper向用户显示flash消息,我需要显示默认flash消息的部分视图。我该怎么做,或者这可能吗?

我需要这样的帮手:

Flash.Success("_FlashMessagePartial",model)

或者有你建议的图书馆吗?

你不能这样使用它。如果我理解正确,您希望向用户显示类似通知的内容,并且不希望刷新页面。正确的答案是你可以做到,但它是不正确的。您的代码看起来一团糟,您将有一个隐藏的通知字段,依此类推。这取决于你想完成什么。例如:我在我的布局中使用全局通知,我的截图看起来像这样

在布局的顶部,就在我放置了一个 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. 

另一个选项,如果你需要在客户端进行一些模型状态验证,你可以寻找由视图模型的属性驱动的js-unobtrusive验证,它使你在客户端进入服务器之前自动检查。

第三个选项是,如果您需要其他通知,您可以使用名为 toastr 的 JS 库。示例库网址 它轻巧且非常易于使用

希望这个答案能准确地解释你需要什么。