ASP.Net MVC: Loading Bootstrap Modal Dialog content with jquery ajax.
Whenever i tried t find how to load the bootstrap modal dialog content at runtime, i was unable to find proper solution anywhere.
One way to do it but in that you have no contrl over the error as bootstrap automatically do that.
$(".opentutorial").click(function (e) {
e.preventDefault();
$('#modalHelpDiv').load(anyurl);
$('#modalHelpDiv').modal({ show: true, keyboard: false });
//.dialog(opt).dialog("open");
});
Second way is this and as per me this second way is the best.
<div id="modalDiv" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-href="anyurl"></div>
$('.previewbtn').click(function () {
var url = $(this).attr('data-href');
$.ajax({
type: "GET",
url: url ,
success: function (resultdata) {
//$('#gameContainer').html(resultdata);
$('#modalDiv').html("");
$('#modalDiv').html(resultdata);
$('#modalDiv').modal({ show: true });
},
error: function (errorThrown) {
//show the error to user
}
});
One way to do it but in that you have no contrl over the error as bootstrap automatically do that.
$(".opentutorial").click(function (e) {
e.preventDefault();
$('#modalHelpDiv').load(anyurl);
$('#modalHelpDiv').modal({ show: true, keyboard: false });
//.dialog(opt).dialog("open");
});
Second way is this and as per me this second way is the best.
<div id="modalDiv" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-href="anyurl"></div>
$('.previewbtn').click(function () {
var url = $(this).attr('data-href');
$.ajax({
type: "GET",
url: url ,
success: function (resultdata) {
//$('#gameContainer').html(resultdata);
$('#modalDiv').html("");
$('#modalDiv').html(resultdata);
$('#modalDiv').modal({ show: true });
},
error: function (errorThrown) {
//show the error to user
}
});
Comments
Post a Comment