要使用jQuery仅上传HTML 5,并非所有的浏览器都能够这样做。
你可以做这样的事情。
您需要有一个IFRAME用于使用该文件创建帖子。
像这样:
在表单你的目标设定在iframe中。
和一个提交按钮
这是上传不刷新页面文件的方式。
你可以在使用jquery上传之前对待这些文件。 (文件类型,大小等)
而且在YOUT控制器,你recive文件:
public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
//Save the file in the server path
string savePath = Server.MapPath("~/Upload/");
string fileName = file.FileName;
savePath += fileName;
file.SaveAs(savePath);
}
return RedirectToAction("Index");
}