2

我有一个 Asp.net 页面,您可以从中上传我需要在代码隐藏中处理和上传的图片。现在,如果我尝试获取所有上传的文件, Request.Files我的计数为 0。如果我使用 javascript 检查,那么它确实告诉我有一个文件,那么我怎样才能在代码隐藏中获取该文件?

ASP.NET 代码

<div class="custom-file">
   <input type="file" ID="FileUploadPictureStudent" class="custom-file-input"
   aria-describedby="FileUploadPictureStudent"name="FileUploadPictureStudent" runat="server"
   onchange="fileUploadhandeler(this);" />
   <asp:Label runat="server" class="custom-file-label" for="FileUploadPictureStudent" Text="Choose file" ID="Fileuploadhelper"></asp:Label>
</div>

VB.Net代码

Dim HelperLabel = Request.Files.Count.ToString()

输出页为 0

document.getElementById('FormViewAddStudent_FileUploadPictureStudent').files在控制台中使用命令输出 Javascript

FileList {0: File, length: 1, item: function} = $1

提前致谢

4

1 回答 1

0

根据我的评论,OP 已确认他们正在尝试在<asp:UpdatePanel>.

不幸的是,这不起作用,因为 UpdatePanel 使用 AJAX 传输数据,并且出于浏览器安全原因,文件不能成为其中的一部分。

您的主要选择是在上传文件时(使用 a )使页面进行完整的回发<Triggers><asp:PostBackTrigger>,尽管我完全理解这是否不会产生出色的 UI。

另一种选择是将文件上传到单独的.aspx文件中,并通过<iframe>...显示在屏幕上,但同样,这有许多缺点。

于 2020-08-18T14:44:09.977 回答