上传图片并没有给我浏览器选择图片的选项

本文关键字:选择 选项 浏览器 并没有 | 更新日期: 2023-09-27 18:05:14

[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
     try
     {
         var _Img = new ImageBusiness();
         var imge = new ImgView { FileName = file.FileName, FileType = file.ContentType };
         imge.FileData = new byte[file.ContentLength];
         file.InputStream.Read(imge.FileData, 0, file.ContentLength);
         _Img.AddImge(imge);
         ViewBag.Result = true;
         return View ();
     }
     catch(Exception)
     {
         ModelState.AddModelError("","An error accured while uploading Image, please try again.");
         return View();
     }           
}

this my view

@using (Html.BeginForm("Upload", "Image", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary();
    <input  name="file" /><br />
    <input type="submit" class="btn btn-small" value="Save Brochure" />
}

没有bug,只是在运行时上传图片时没有给我浏览器选择图片的选项。感谢您的帮助

上传图片并没有给我浏览器选择图片的选项

你好,我想你可能在输入时缺少类型文件试试

<input type="file" name="file" /><br />
<input type="submit" class="btn btn-small" value="Save Brochure" />