我有一个引导模式 ,可以从不同的超链接启动,每个供应另一个ID。
但我想是每一个模态启动时,它填充了传递给此模式的ID数据。 这里是(简化)代码(见解释的代码中的注释):
@model ViewModels.BookcaseItem.EditBookcaseItemViewModel
<div class="modal hide modal-large" id="editBookDialog">
@using (Html.BeginForm("Edit", "Bookcase", FormMethod.Post, new { @class = "form-horizontal" }))
{
<!-- this is where the ID will be passed to -->
@Html.HiddenFor(x => x.Id)
<div class="modal-body">
<!-- there's actually a couple of editors and labels here, but that doesn't really matter -->
@Html.EditorFor(x => x.Bla)
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<input type="submit" value="Save" class="btn btn-primary" />
</div>
}
</div>
这里是用来启动模式和ID传递给它的超链接之一:
<a href="#editBookDialog" data-toggle="modal" data-id="@bookcaseItem.Id" title="Edit this item" class="open-EditBookDialog"></a>
最后但并非最不重要的部分JQuery的实际传递ID:
$(document).on("click", ".open-EditBookDialog", function () {
var myBookcaseItemId = $(this).data('id');
$(".modal #Id").val(myBookcaseItemId);
$('#editBookDialog').modal('show');
});
让我们假设有一个与返回的数据,其中模式被放置在PartialView签名的ActionResult编辑(字符串ID)的方法。
该模式已经被嵌入到所有的超链接的页面,它只是默认情况下不可见。
我只是无法弄清楚如何使用基于所传递的ID的不同的数据来填充它。