我有一个动作链接,我想从中调用模式窗口。但是为此,我需要调用脚本,但是无法像在href中那样调用它。
使用href我使用data-modal =“”参数,我可以调用脚本,但是在actionLink中,我不能
href示例:
<a href="@Url.Action("Edit",Boats", new { id = item.Id })" class="btn btn-warning" data-modal="">
<span class="fa fa-edit"></span>
</a>
ActionLink和脚本:
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
@Html.AntiForgeryToken()
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "ChangePassword", "Manage")
}
}
<div id="myModal" class="modal fade in">
<div class="modal-dialog">
<div class="modal-content">
<div id="myModalContent"></div>
</div>
</div>
</div>
$(function () {
$.ajaxSetup({ cache: false });
$("a[data-modal]").on("click", function (e) {
$('#myModalContent').load(this.href, function () {
$('#myModalLogin').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) {
$('#myModal').modal('hide');
$('#replacetarget').load(result.url);
} else {
$('#myModalContent').html(result);
bindForm(dialog);
}
}
});
return false;
});
}