【问题标题】:ASP.NET MVC4 multiple file upload not work from mobileASP.NET MVC4 多文件上传在移动设备上不起作用
【发布时间】:2016-09-03 14:25:16
【问题描述】:

我有如下代码,你可以从url进入网站:http://nirh1989-001-site1.itempurl.com/

当我从桌面打开 url 时,我可以一次上传多个文件,但是当我从移动浏览器打开 url 时,我一次只能上传一个文件。

为什么?

Index.cshtml:

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="container">
        <div class="form-horizontal">
            <div class="form-group">
                <p></p>
                <label for="file">Upload Photo:</label>
                <input type="file" name="file" id="file" accept="image/*" multiple="multiple" required />
            </div>
            <div class="form-group">
                <div>
                    <input type="submit" value="Upload" class="btn btn-default" />
                </div>
            </div>
        </div>
    </div>
    <hr />

    <div class="gallery">
        @if (ViewBag.Images != null)
        {
            var imgID = 0;
            foreach (var image in (IEnumerable<string>)ViewBag.Images)
            {
                imgID++;
                <a class="fancybox" rel="group" href="@Url.Content(image)">
                    <img id="@imgID" src="@Url.Content(image)" style="height: 100px; width: 100px;" />
                </a>
            }
        }
    </div>
}

控制器:

public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            ViewBag.Images = Directory.EnumerateFiles(Server.MapPath("/Content/Photos")).Select(f => "/Content/Photos/" + Path.GetFileName(f));
            return View();
        }

        //POST: Home
        [HttpPost]
        public ActionResult Index(IEnumerable<HttpPostedFileBase> file)
        {
            if (file != null)
            {
                foreach (var item in file)
                {
                    string fileName = Path.GetFileName(item.FileName);
                    string imgPath = Server.MapPath("~/Content/Photos/");

                    item.SaveAs(imgPath + fileName);
                }
            }
            ViewBag.Images = Directory.EnumerateFiles(Server.MapPath("/Content/Photos")).Select(f => "/Content/Photos/" + Path.GetFileName(f));
            return View();
        }
    }

【问题讨论】:

  • 尝试将multiple 属性添加到输入文件控件。
  • 输入文件已经有multiple属性(否则我无法从桌面上传多个文件)

标签: c# asp.net-mvc mobile file-upload


【解决方案1】:

显然我的代码没有任何问题...问题出在手机上,我尝试从手机中的文件夹上传多个文件,由于某种原因不允许多项选择...尝试从图库和所有内容上传没问题

【讨论】:

    猜你喜欢
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2022-01-12
    • 2014-04-22
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    相关资源
    最近更新 更多