所以第一個動作是:
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new { enctype = "multipart/form-data" }))
第二個是ajax呼叫:
<input type="submit" value="Save" onclick="deleteImages()" />
阿賈克斯:
<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函式被呼叫,而Post/Editof theHtml.BeginForm沒有。對于如何解決這個問題,有任何的建議嗎?
uj5u.com熱心網友回復:
你可以使用onsubmit. 在發布前運行 onsubmit
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new
{ onsubmit="deleteImages()", enctype = "multipart/form-data" }))
第二個選項:(使用jquery)
$('form').submit(function() {
deleteImages();
return true;
});
uj5u.com熱心網友回復:
@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new { enctype = "multipart/form-data" }))
也許您缺少區域?
就像是
@using (Html.BeginForm("Edit", "Post", new { area = "" }, FormMethod.Post, new { enctype = "multipart/form-data" }))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/496590.html
標籤:javascript C# 网 阿贾克斯 asp.net-mvc
