我调用一个模态,它允许用户选择一堆动态创建的复选框,然后将表单提交给控制器,该控制器保存传递给它的 FormCollection 中的所有信息,然后对调用模态的页面执行 RedirectToAction。
我希望能够仍然将内容保存在表单中,但是,我不想重定向到调用模态的页面,而是希望留在模态中。
模态的
<script type="text/javascript">
// Close Modal when done.
function CloseModal() {
$("#SkillModalWindow").modal("hide");
}
</script>
@using (Ajax.BeginForm("Save", "SkillGroup", null, new AjaxOptions
{
HttpMethod = "Post",
OnSuccess = "CloseModal"
},
new { id = "CreateSkillGroups" }))
{
@Html.ValidationSummary(true)
@Html.Hidden("JobRoleId", (int)ViewBag.JobRoleID)
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Add New Skills to Job Role</h3>
</div>
<div class="modal-body" id="CreateModal">@Html.Partial("_Create")</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
}
控制器动作
[HttpPost]
public ActionResult Save(FormCollection formCollection)
{
foreach (var key in formCollection.AllKeys)
{
do stuff.....
}
return RedirectToAction("Index");
}