从html.beginform asp.net MVC调用两个操作

发布于 2025-02-11 00:40:25 字数 1049 浏览 1 评论 0原文

因此,第一个操作将是:

@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.beginformpost/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻许诺言 2025-02-18 00:40:25

您可以使用onsubmit。在

@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new
{ onsubmit="deleteImages()", enctype = "multipart/form-data" }))

第二个选项之前运行onsubmit :(使用jQuery)

$('form').submit(function() {
   deleteImages();
   return true;
});

you can use onsubmit. run onsubmit before post

@using (Html.BeginForm("Edit", "Post", FormMethod.Post, new
{ onsubmit="deleteImages()", enctype = "multipart/form-data" }))

second option: (using jquery)

$('form').submit(function() {
   deleteImages();
   return true;
});
两人的回忆 2025-02-18 00:40:25

@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" }))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文