第一个动作是:
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new { enctype = "multipart/form-data" }))
第二个是ajax调用:
<input type="submit" value="Save" onclick="deleteImages()" class="btn btn-default" />
Ajax:
<script>
let deletedImages = [];
function Remove(id, e) {
deletedImages.push(id);
console.log(deletedImages);
$(e).fadeOut(1000);
$(e).next().fadeOut(1000);
}
//starts here
function deleteImages() {
$.ajax({
type: 'POST',
url: "@Url.Action("DeleteImages", "Image")",
data: { "deletedImages": deletedImages },
success: function(data) {
alert("deleted");
},
error: function(data) {
window.location.reload();
}
});
}
</script>
只有onClick
函数被调用,而Html.BeginForm
的Post/Edit
函数没有被调用。对如何解决这个问题有什么建议吗?
您可以使用onsubmit
。post前运行onsubmit
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new
{ onsubmit="deleteImages()", enctype = "multipart/form-data" }))
第二个选项:(使用jquery)
$('form').submit(function() {
deleteImages();
return true;
});
@using (Html.BeginForm("Edit", "Post", FormMethod;Post, new {enctype = "multipart/form-data"}))
也许你错过了Area?
之类的@using (Html.BeginForm("Edit", "Post", new {area = "}, FormMethod。Post, new {enctype = "multipart/form-data"}))