想要在我的按钮点击事件上上传多个文件 [英] Want ajax multiple file upload on my button click event

查看:128
本文介绍了想要在我的按钮点击事件上上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的.aspx页码

Here is my .aspx page code

 <form id="form1" runat="server">
    <asp:ToolkitScriptManager runat="server">
    </asp:ToolkitScriptManager>
    <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
        Width="400px" OnUploadComplete="OnUploadComplete" Mode="Auto" />
    <asp:Button ID="abc" runat="server" Text="Button" OnClientClick="$('.ajax__fileupload_uploadbutton').trigger('click');" OnClick="abc_Click" />
</form>

.aspx.cs代码是

.aspx.cs code is

 protected void OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        string fileName = Path.GetFileName(e.FileName);
        AjaxFileUpload1.SaveAs(Server.MapPath("~/uploads/" + fileName));
    }
    protected void abc_Click(object sender, EventArgs e)
    {
    // need file upload on this click and also need to store some outer data in this click event
    }

如何在我自己的按钮点击事件上实现ajax多文件上传我需要上传多个文件以及此按钮上的其他一些数据点击

我已经放置了控制html和.cs代码好吧,并使用事件OnUploadComplete上传多个图像,但我需要在abc_Click事件上传图像,以便单击我可以上传图像以及我也可以保存数据

推荐答案

您应该考虑将项目迁移到 ASP.NET MVC 。当向您的代码隐藏发送不同的和多种数据类型时,这会给您带来很多好处。然后你可以创建一个 ViewModel ,它可以保存图片列表以及你需要的其他信息,并在一次通话中将所有信息发送到你的后端。

You should really consider migrating the project to ASP.NET MVC. That would give you a lot of perks, when sending different and multiple data types to your code-behind. Then you can make a ViewModel which can hold a list of the pictures, alongside with the other information you need, and send all the information to your backend in one call.

当然,我不知道你是否已经熟悉MVC,但如果没有,
请参考此链接以获取更多知识:
https://www.asp.net/mvc

Off course, I don't know if you are already experienced in MVC, but if not, refer to this link for more knowledge: https://www.asp.net/mvc

我希望帮助了你一点,否则让我知道。

I hope that helped you a little, else let me know.

这篇关于想要在我的按钮点击事件上上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆