使用Ajax上传文件时出错。HttpPostFileBase始终为空
我使用Ajax.Beginform方法上传文件,但它不工作,请帮助我 文件Create.cshtml:使用Ajax上传文件时出错。HttpPostFileBase始终为空,ajax,Ajax,我使用Ajax.Beginform方法上传文件,但它不工作,请帮助我 文件Create.cshtml: @using (Ajax.BeginForm("UpLoadFile", "KG", new AjaxOptions { HttpMethod = "POST" }, new { enctype = "multipart/form-data", @id = "form-uploadfile" })) { <input type="file" na
@using (Ajax.BeginForm("UpLoadFile", "KG", new AjaxOptions { HttpMethod = "POST" }, new { enctype = "multipart/form-data", @id = "form-uploadfile" }))
{
<input type="file" name="fileupload" id="fileupload" />
<input type="submit" value="UpLoad" />
}
参数fileupload始终为空,我引用了许多帖子,但仍然解决了问题:(
对不起,我的英语很差
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase fileupload)
{
if (fileupload != null)
{
// Verify that the user selected a file
if (fileupload != null && fileupload.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(fileupload.FileName);
// TODO: need to define destination
var path = Path.Combine(Server.MapPath("~/Upload"), fileName);
fileupload.SaveAs(path);
}
}
return Json(new { success = true });
}