【问题标题】:upload a file without having the submit button in mvc在 mvc 中没有提交按钮的情况下上传文件
【发布时间】:2014-04-09 01:11:40
【问题描述】:
I want to upload a file without using the submit button. The file must be uploaded at the moment the user picks it from browse file window.

现在请提供一些 ajax 代码或一些 jquery 来上传文件以及如何删除文件。

Please provide the control view for this.
View>>>

<form action="FileUploadPost" method="post" enctype="multipart/form-data">

        <label for="file1">Filename1:</label>
        <input type="file" name="files" id="file3" />

        <label for="file2">Filename2:</label>
        <input type="file" name="files" id="file4" />

</form>

控制器>>>

[HttpPost]
        public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
        {
            foreach (var file in files)
            {
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(HttpContext.Server.MapPath("~/App_Data/Uploads"), fileName);
                    file.SaveAs(path);
                }
            }
            return RedirectToAction("Index");
        }

【问题讨论】:

    标签: javascript jquery asp.net-mvc asp.net-mvc-4 file-upload


    【解决方案1】:

    您可以使用 JQuery 文件上传器控件来满足您的要求。 它提供了“通过单击按钮”和“自动上传”上传文件的功能。

    自动上传:此功能将在您选择文件后立即上传文件。

    请参阅Ajax File Upload 了解分步实施。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 2010-12-26
      • 1970-01-01
      • 2021-12-20
      相关资源
      最近更新 更多