1

我有以下代码来上传文件,该文件在 mozilla firefox 和 google chrome 中运行没有错误,但在 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);
    }
4

0 回答 0