文件上传在IE 8,IE 9中不起作用

时间:2012-11-29 10:18:12

标签: asp.net-mvc-3 file-upload

我有以下代码上传文件,在mozilla firefox和谷歌浏览器中运行没有错误,但在IE 8中出错。请提供解决方案。这是我的观点 -

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <fieldset>
        <div class="input_panelleft">
            <div class="input_panellabel">
                @Html.LabelFor(model => model.DrawingName)
            </div>
            <div class="input_panelinput">
                @Html.EditorFor(model => model.DrawingName)
            </div>
            <div class="input_panellabel">
                Upload Drawing
            </div>
            <div class="input_panelinput">
                <input type="file" name='file' id='file' />
            </div>
            <div class="center">
                <input type="submit" value="Upload" />
            </div>
        </div>
    </fieldset>
}

以及控制器中的代码 -

 [HttpPost]
    public ActionResult Create(DrawingDocumentsModel model, HttpPostedFileBase file)
    {
        if (ModelState.IsValid)
        {
            if (file != null)
            {
                var documentNameParts = file.FileName.Split('.');
                var documentExtension = documentNameParts.Last();
                var documentNameOnly = String.Join(".", documentNameParts.Take(documentNameParts.Length - 1));
                var filename = documentNameOnly + "." + documentExtension;
                if (_drawingDocumentService.IsDrawingNameAvailable(filename))
                {
                    var path = Server.MapPath("~/Uploads/");
                    var Filepath = Path.Combine(path, filename);
                    file.SaveAs(Filepath);

                    var drawingDocuments = new DrawingDocuments();
                    drawingDocuments.ProjectId = 1;
                    drawingDocuments.ProjectName = "Drawing Tag";
                    drawingDocuments.FileName = filename;
                    drawingDocuments.UploadedDate = System.DateTime.Now;
                    drawingDocuments.UploadedBy = _workContext.CurrentUserId;
                    if (model.DrawingName == "" || model.DrawingName == null)
                    {
                        ModelState.AddModelError("CustomError", "Please Enter Drawing Name");
                    }
                    else
                    {
                        drawingDocuments.DrawingName = model.DrawingName;
                        drawingDocuments.Path = ("/Uploads/" + filename);

                        _drawingDocumentService.InsertDrawingDocument(drawingDocuments);
                        return RedirectToAction("DrawingDocuments");
                    }
                }
                else
                {
                    ModelState.AddModelError("CustomError", "Drawing With Same File Name Already Available");
                }
            }
            else
            {
                ModelState.AddModelError("CustomError", "Please Select Drawing");
            }
        }

        return View(model);
    }

0 个答案:

没有答案