文件已被选定后,如何自动上传文件 [英] How to automatically upload file after file has been chosen

查看:255
本文介绍了文件已被选定后,如何自动上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code在我的网站上载文件:

I have the following code for uploading a file in my site:

@using (Html.BeginForm("UploadProfileImage", "Member", FormMethod.Post, new { @encType = "multipart/form-data" }))
   {

     @Microsoft.Web.Helpers.FileUpload.GetHtml(initialNumberOfFiles: 1, includeFormTag: false, uploadText: "Upload File",allowMoreFilesToBeAdded:false)
    <span class="success">@ViewData["SuccessMessage"]</span>
     <input class="button" type="submit" name="submit" value="Upload" />         

}

我希望这能够自动发布用户从浏览按钮后的文件。目前,用户必须点击上传每个用户选择要上传的文件的时间,反正让这个过程自动化?

I want this to be able to automatically post after the user selects the file from the "browse" button. Currently, the user has to click upload every time the user chooses a file to upload, anyway to make this process automatic?

推荐答案

文件上传控件支持的onchange 事件。希望可用于触发载

The file upload control supports onchange event. Hope that can be used to trigger the upload

<form name="upload" action="uploadfile.aspx" method="POST">
    <input name="myfile" type="file" onchange="UploadFile()" />
</form>

<script>
   function UploadFile()
   {
      //do validation here
      document.forms['upload'].submit();
   }
</script>

这篇关于文件已被选定后,如何自动上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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