So the first action would be:
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new { enctype = "multipart/form-data" }))
and the second would be a ajax call:
<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>
Only the onClick
function is getting called, whereas the Post/Edit
of the Html.BeginForm
is not.
Any suggestions on how to fix this?
2
Answers
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new { enctype = "multipart/form-data" }))
Maybe you are missing Area?
Something like
@using (Html.BeginForm("Edit", "Post", new { area = "" }, FormMethod.Post, new { enctype = "multipart/form-data" }))
you can use
onsubmit
. run onsubmit before postsecond option: (using jquery)