Created
July 7, 2013 17:39
-
-
Save rohitkandhal/5944261 to your computer and use it in GitHub Desktop.
Modal dialog view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<!-- Project General Details Section --> | |
<div class="row span11"> | |
@Html.ActionLink("Create", "Create", "Project", | |
new { id = 1 }, | |
new { id = "btnCreate", @class = "btn btn-primary modal-link" }) | |
@Html.ActionLink("Edit", "Edit", "Project", | |
new { id = 1 }, | |
new { id = "btnAdd", @class = "btn btn-success modal-link" }) | |
@Html.ActionLink("Delete", "DeleteProject", "Home", | |
new { id = 1 }, | |
new { id = "btndelete", @class = "btn btn-danger modal-link" }) | |
</div> | |
<!-- Please note this modalDiv should be declared outside of whole view. --> | |
<div id="modalDiv" class="modal hide fade in" > | |
<div id="modalContent"></div> | |
</div> | |
<script type="text/javascript"> | |
$(function () { | |
$.ajaxSetup({ cache: false }); | |
$('#btnAdd').click(function () { | |
$('#modalContent').load(this.href, function () { | |
$('#modalDiv').modal({ | |
backdrop: 'static', | |
keyboard: true | |
}, 'show'); | |
bindForm(this); | |
}); | |
return false; | |
}); | |
// See how to bind all action links with class name - Modal Link to dialogs. | |
// http://stackoverflow.com/a/10390622/351708 | |
// Above example shows how to use individual links | |
$('.modal-link').click(function () { | |
$('#modalContent').load(this.href, function () { | |
$('#modalDiv').modal({ | |
backdrop: 'static', | |
keyboard: true | |
}, 'show'); | |
bindForm(this); | |
}); | |
return false; | |
}); | |
}); | |
function bindForm(dialog) { | |
$('form', dialog).submit(function () { | |
$.ajax({ | |
url: this.action, | |
type: this.method, | |
data: $(this).serialize(), | |
success: function (result) { | |
if (result.success) { | |
$('#modalDiv').modal('hide'); | |
// Refresh: | |
location.reload(); | |
} else { | |
$('#modalContent').html(result); | |
bindForm(); | |
} | |
} | |
}); | |
return false; | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment