简体   繁体   English

Bootstrap 文件上传不适用于 ASP Ajax AsyncFileUpload

[英]Bootstrap file upload not working with ASP Ajax AsyncFileUpload

So I am having an issue on my ASP web form, where I am using Bootstrap and trying to make use of the Ajax AsyncFileUpload control.所以我在我的 ASP web 表单上遇到问题,我在其中使用 Bootstrap 并尝试使用 Ajax AsyncFileUpload 控件。 The file upload control looks like this:文件上传控件如下所示:

<div id="LoafFileUploadTemplate" class="custom-file">
    <asp:AsyncFileUpload ID="LoafFileUpload" runat="server" ClientIDMode="Static" CssClass="custom-file-input file-upload" enctype="multipart/form-data" method="post" OnClientUploadStarted="Loaf_UploadStarted" OnClientUploadComplete="Loaf_UploadComplete" OnUploadedComplete="LoafFileUpload_UploadedComplete" />
    <label class="custom-file-label">Choose File</label>
</div>
<asp:Button ID="LoafFileUploadComplete" runat="server" ClientIDMode="Static" CssClass="d-none" OnClick="LoafFileUploadComplete_Click" />

For some reason the LoafFileUpload_UploadedComplete method didn't fire when the uploader was finished.出于某种原因,当上传器完成时,LoafFileUpload_UploadedComplete 方法没有触发。 I've read that I need to add enctype="multipart/form-data" method="post" to the file input.我读到我需要将enctype="multipart/form-data" method="post"添加到文件输入中。 I have done that, but still doesn't work.我已经这样做了,但仍然不起作用。 Turns out the way bootstrap renders the AsyncFileUpload control, these two attributes get applied to a div instead of the file upload control, as seen below:事实证明,bootstrap 呈现 AsyncFileUpload 控件的方式,将这两个属性应用于 div 而不是文件上传控件,如下所示:

<div id="LoafFileUploadTemplate" class="custom-file">
<div id="LoafFileUpload" class="custom-file-input file-upload" enctype="multipart/form-data" method="post">
    <input type="hidden" name="ctl00$CPH_main$CsatoltFajlok$LoafFileUpload$ctl00"><div><input name="ctl00$CPH_main$CsatoltFajlok$LoafFileUpload$ctl02" type="file" id="ctl00_CPH_main_CsatoltFajlok_LoafFileUpload_ctl02" style="" size="20"></div>
</div>
<label class="custom-file-label">Fájl feltöltése</label>
</div>
</div>
<input type="submit" name="ctl00$CPH_main$CsatoltFajlok$LoafFileUploadComplete" value="" id="LoafFileUploadComplete" class="d-none">

So as seen here, the enctype="multipart/form-data" method="post" attributes are applied onto the div containing the file input, not the input itself.因此,如此处所示, enctype="multipart/form-data" method="post"属性应用于包含文件输入的 div,而不是输入本身。 Because of this, the file doesn't get posted to the server.因此,该文件不会发布到服务器。 Anyones know a fix for this?有人知道解决这个问题吗?

Turns out I didn't need to add enctype="multipart/form-data" method="post" to the file input, but to the form itself (in my case, in the master page).原来我不需要将enctype="multipart/form-data" method="post"添加到文件输入,而是添加到表单本身(在我的例子中,在母版页中)。 It works now.现在可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 文件上载控件和Ajax AsyncFileUpload控件 - File Upload control and Ajax AsyncFileUpload control 使用Ajax asyncfileupload上传,重命名和显示图像-ASP.NET - Upload, rename and display the image with Ajax asyncfileupload - ASP.NET Ajax控件工具包AsyncFileUpload在Azure上的文件上传控制 - Ajax control toolkit AsyncFileUpload file upload contol on azure Asp.Net Ajax工具包AsyncFileUpload-“附加的文件无效”错误 - Asp.Net Ajax Toolkit AsyncFileUpload - “The file is attached is invalid” error AsyncFileUpload 限制上传的文件大小 - AsyncFileUpload restrict file size to upload 保存时ajax中缺少文件:AsyncFileUpload - File missing in ajax:AsyncFileUpload on saving 上传前如何验证ajax工具包AsyncFileUpload控制文件的大小和扩展名 - How to validate ajax toolkit AsyncFileUpload Control file size and extension before upload asp.net GridView和Ajax控件-AsyncFileUpload - asp.net GridView and ajax control -AsyncFileUpload 如何在ASP.NET AJAX控件工具包中的AsyncFileUpload的文件浏览菜单中限制文件类型 - How can I restrict the file type in the file browse menu of an AsyncFileUpload in the ASP.NET AJAX Control Toolkit 在updatepanel asp.net c#中的AsyncFileUpload中上传文件后显示gridview - display gridview after upload file in AsyncFileUpload in updatepanel asp.net c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM