前言:该问题涉及到ASP.NET MVC 3.0(发布于2011年),不是关于2019年发布的ASP.NET Core 3.0。
我想在ASP.NET MVC中上传文件。如何使用HTML input file
控件来上传文件?
前言:该问题涉及到ASP.NET MVC 3.0(发布于2011年),不是关于2019年发布的ASP.NET Core 3.0。
我想在ASP.NET MVC中上传文件。如何使用HTML input file
控件来上传文件?
我在进行文件上传时遇到了同样的错误。我知道很多开发人员为这个问题提供了答案。
尽管如此,我回答这个问题的原因是,由于下面提到的粗心错误,我也遇到了这个错误。
<input type="file" name="uploadedFile" />
[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase uploadedFile)
{
}
if (MyModal.ImageFile != null)
{
MyModal.ImageURL = string.Format("{0}.{1}", Guid.NewGuid().ToString(), MyModal.ImageFile.FileName.Split('.').LastOrDefault());
if (MyModal.ImageFile != null)
{
var path = Path.Combine(Server.MapPath("~/Content/uploads/"), MyModal.ImageURL);
MyModal.ImageFile.SaveAs(path);
}
}
<input type="hidden" value="" name="..."><input id="ImageFile" type="file" name="ImageFile" src="@Model.ImageURL">
public HttpPostedFileBase ImageFile { get; set; }