更新网页后显示弹出屏幕

时间:2015-05-07 20:48:00

标签: jquery html css asp.net-mvc twitter-bootstrap

目标: 当我更新或添加新数据时,我希望更新网页,然后会自动出现一个弹出屏幕。文本是" test"

问题是我不知道怎么做。

是否可以使用bootstrap而不是twitter bootstrap来实现?

今天,我使用了boostrap和asp.net mvc。

http://www.sitepoint.com/twitter-bootstrap-3-javascript-components/

public ActionResult Contact()
{
    ViewBag.Message = "Your contact page.";

    ViewBag.Product = "Test";

    return View();
}

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要通过向服务器发送新请求来保留消息,您可以通过多种方式执行此操作。您可以使用tempdata,session,DB或手动将其传递给操作。我通常使用tempdata,它就像ViewBag,但是持续通过另一个请求:

public ActionResult Contact()
{
    ViewBag.Message = "Your contact page.";

    TempData["Product"] = "Test";

    return View();
}

在视图中:

@if (TempData["Product"] != null)
{
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
          </div>
          <div class="modal-body">
            @TempData["Product"]
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>

    <script>$('#myModal').modal();</script>
}

此示例代码查看是否有消息,如果有,它会将模式HTML放在包含您的消息的页面上。还有其他方法可以做到这一点。

确保在此小脚本运行之前,页面上引用了引导CSS和JS文件。

相关问题