简体   繁体   English

如何防止 Bootstrap Modal 自动关闭?

[英]How to prevent the Bootstrap Modal from auto closing?

I have bootstrap modal (opened by button) in "Index" View in my ASP.NET MVC web app.我在 ASP.NET MVC web 应用程序的“索引”视图中有引导模式(通过按钮打开)。 In this modal I call stored procedure (with input parameter) which fill three texboxes.在这个模式中,我调用填充三个 texbox 的存储过程(带有输入参数)。 After that my modal closes automatically.之后我的模式自动关闭。 When I open it again the texboxes are filled.当我再次打开它时,texboxes 被填满了。 How can I prevent this auto closing?如何防止这种自动关闭?

Part of my "Index" view with stored procedure:带有存储过程的“索引”视图的一部分:

<!-- Input parameter to execute stored procedure "GetMesData" -->
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
@Html.TextBox("send")
<input type="submit" value="Send" />
}

<!-- Textboxes which are fill thanks to stored procedure "GetMesData" -->
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<br>@Html.TextBoxFor(x => x.UserResponse.MatNumber, Model.UserResponse.MatNumber.ToString())<br />
<br>@Html.TextBoxFor(x => x.UserResponse.SlurryNumber, Model.UserResponse.SlurryNumber.ToString())<br />
<br>@Html.TextBoxFor(x => x.UserResponse.BatchNumber, Model.UserResponse.BatchNumber.ToString())<br />
}

JavaScript - probably i should add something here to prevent this auto closing JavaScript - 可能我应该在这里添加一些东西来防止这种自动关闭

<script>
$(document).ready(function(){
  $("#myBtn").click(function(){
      $("#myModal").modal('show');
  });
});
</script>

My "Home" controller method post:我的“家”controller 方法帖子:

//Execute stored procedure "GetMesData" with input parameter
[HttpPost]
public ActionResult Index(OrderListOfClass ttt, string send)
{

//calling stored procedure

return View()
}

To prevent closing bootstrap modal when click outside using jQuery.为了防止使用 jQuery 在外部单击时关闭引导模式。 You have to use option backdrop to static option and keyboard to false option.您必须将选项背景用于 static 选项,将键盘用于 false 选项。 This works after you click on the button and open modal.这在您单击按钮并打开模式后有效。

$('#MymodalPreventScript').modal({ backdrop: 'static', keyboard: false }); $('#MymodalPreventScript').modal({ 背景:'静态',键盘:假 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM