当我按下提交按钮时,Sweetalert弹出。当我按OK时,页面将我重定向到索引页面,但数据未发布到数据库中。
这是我的控制者:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit([Bind(Include ="TaskId,Title,Description,CreatedDate,Deadline,StatusId,ProjectId,Comment")]
OGP_PEG_.Models.Task task)
{
if (ModelState.IsValid)
{
db.Entry(task).State = EntityState.Modified;
await db.SaveChangesAsync();
}
ViewBag.ProjectId = new SelectList(db.Projects, "IdProvisional",
"Title", task.ProjectId);
ViewBag.StatusId = new SelectList(db.ProjectStatus, "StatusId",
"StatusType", task.StatusId);
return View(task);
}
这是要提交的JQuery代码:
$('#taskbtn').click(function (e) {
e.preventDefault();
var data = $(this).closest("form");
swal({
title: "Gracias!",
text: "Su comentario a sido grabado.",
icon: "success",
buttons: {
cancel: true,
confirm: "Submit",
closeOnConfirm: false
},
}).then(function () {
e.preventDefault();
if (data != null) {
swal({
text: data,
icon: "success"
});
data.submit();
window.location.href = "/Tasks/Index";
}
});
});
我的观点:
@using (Html.BeginForm("Edit", "Tasks"))
{
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input id="taskbtn" type="submit" name="Comment" value="Save" class="btn btn-default" />
</div>
</div>
}
编辑通话:
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.TaskId }) |
@Html.ActionLink("Details", "Details", new { id = item.TaskId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.TaskId })
</td>