ASP.NET MVC4多文件上传无法在移动设备上运行

时间:2016-09-03 14:25:17

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

我有以下代码,您可以从网址输入网站:https://appleonlinefra.mpxltd.co.uk/Inspection.aspx

当我从桌面打开网址时,我可以一次上传多个文件,但是当我从手机浏览器打开网址时,我一次只能上传1个文件。

为什么?

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();
        }
    }

1 个答案:

答案 0 :(得分:0)

显然我的代码没有问题...问题是手机,我试图从手机中的文件夹上传多个文件,由于某种原因不允许多种选择...试图从图库和一切上传没关系