简体   繁体   中英

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. In this modal I call stored procedure (with input parameter) which fill three texboxes. After that my modal closes automatically. When I open it again the texboxes are filled. 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

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

My "Home" controller method post:

//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. You have to use option backdrop to static option and keyboard to false option. This works after you click on the button and open modal.

$('#MymodalPreventScript').modal({ backdrop: 'static', keyboard: false });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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