显示Bootstrap无效警报

时间:2019-02-28 14:02:32

标签: html asp.net-mvc twitter-bootstrap entity-framework alert

我试图使用ViewBag从控制器显示成功的Bootstrap警报,但是,一旦我导航到该页面,就会显示“关闭”按钮:

enter image description here

一旦保存更改,它便会正确显示警报:

enter image description here

导航到页面时如何摆脱关闭状态?

代码:

控制器

            ViewBag.Message = "Definition Successfully Saved!";
            ViewBag.AlertClass = "alert alert-success alert-dismissible";
            ViewBag.AlertVisibility = "";

查看

<div class="@ViewBag.AlertClass">
<button type="button" class="close" data-dismiss="alert">close</button>
<h4 class="@ViewBag.AlertVisibility text-center"><span class="glyphicon glyphicon-ok-sign"></span> @ViewBag.Message</h4>

1 个答案:

答案 0 :(得分:0)

引导警报必须是这样的:

<div class="@ViewBag.AlertClass fade" role="alert">
  <h4 class="text-center"><span class="glyphicon glyphicon-ok-sign"></span> 
       @ViewBag.Message</h4>
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

因此C#代码中的 ViewBag.AlertClass 应该等于:

ViewBag.AlertClass = "alert alert-success alert-dismissible show";

据我所知,您不需要 ViewBag.AlertVisibility ,因为 show 类具有该角色。

相关问题