目标:更新或添加新数据后,我想更新网页,然后会自动出现一个弹出屏幕。文字是“测试”
问题是我不知道该怎么做。
是否可以通过使用引导程序而不是Twitter引导程序来做到这一点?
今天,我正在使用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();
}
您需要通过对服务器的新请求来保留消息,您可以通过多种方法进行处理。您可以使用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">×</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文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句