从html.beginform asp.net MVC调用两个操作
因此,第一个操作将是:
@usus(html.beginform(“ edit”,“ post”,formMethod.post,new {enctype =“ zultypart/form-data”}))
将是一个ajax调用:
&lt; input type =“ submit” value =“ save” onclick =“ deleteimages()” class =“ btn btn-default” /&gt; < /&code>
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
却没有。 关于如何解决此问题的任何建议?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
onsubmit
。在第二个选项之前运行onsubmit :(使用jQuery)
you can use
onsubmit
. run onsubmit before postsecond option: (using jquery)
@using(html.beginform(“ edit”,“ post”,formMethod.post,new {enctype =“ supterypy/form-data”}))
也许您缺少区域?
类似于
@using(html.beginform(“ edit”,“ post”,new {abreat =“”},formMethod.post,new new {enctype =“ multipart/form-data”}))
@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" }))