jquery Razor Page -表单未提交

ni65a41a  于 2023-02-21  发布在  jQuery
关注(0)|答案(1)|浏览(181)

我目前正在Razor Page(.NET Core 6)上工作,遇到的问题是表单(本例中为“form_Download")不提交,奇怪的是我在其他页面中也有类似的代码,而且工作正常,我想知道为什么表单不提交,以下是我的代码:

常规.cshtml

@page "{order_id}"
@model MyNameSpace.Pages.OrderSheet.Approve.GeneralModel
...
<form id="form_update" method="post" /> @*used for other post methods*@
...
<form id="form_Download" method="post" asp-page-handler="DownloadAttachment">
    <input id="hdn_AttachId" name="attach_id" type="hidden" />
</form>
@section Scripts {
    <script src="~/lib/DevExtreme/dx.all.js"></script>
    <script type="text/javascript">

        const formUpdate = document.querySelector("#form_update");

        $(() => {

            //...

            $('#grid_Attachment').dxDataGrid({
                dataSource: attachmentStore,
                columns: [{
                    caption: 'No',
                    dataField: 'attach_id',
                }, {
                    caption: 'Type',
                    dataField: 'type',
                }, {
                    caption: 'Name',
                    dataField: 'file_name',
                    cellTemplate(cell, info) {
                        const { data: { attach_id, file_name, file_extension } } = info.row;
                        $('<div>')
                            .html(`<a href="#" class="dx-link dx-link-edit" onclick="DownloadAttachment(${attach_id})">${file_name}${file_extension}</a>`)
                            .appendTo(cell);
                    },
                }, {
                    caption: 'Remark',
                    dataField: 'remark',
                }],
                remoteOperations: false,
                showBorders: true,
            });
        });

        //...

        function DownloadAttachment(attach_id) {
            $("#hdn_AttachId").val(attach_id);
            $("#form_Download").submit();
        }
    </script>
}

一般信息.cshtml.cs

public class GeneralModel : PageModel
{
    //...

    public IActionResult OnPostDownloadAttachment(int order_id, int attach_id)
    {
        (byte[] bytes, string contentType, string filename) = _attachmentManager.DownloadFile(order_id, attach_id)!;
        return File(bytes, contentType, filename);
    }
}
s3fp2yjn

s3fp2yjn1#

好的。我刚刚在我的代码中发现了一个错误。看起来表单不允许使用/>作为结束标记(我在form_update上使用了它)。所以在我改为使用</form>之后,现在它可以正常工作了。

<form id="form_update" method="post"></form>

相关问题