【发布时间】:2015-08-20 20:35:45
【问题描述】:
我有一个控制器用于上传任何类型的文件。它的精简版是
[HttpPost]
public ActionResult Index (HttpPostedFileBase file, string selectedOrgName, string selectedCatName, string previouslyUploadedFilesJSON = null)
{
// ...... bunch of stuff
try
{
file.SaveAs(newFileServerPathAndName); // Saves file with new file name in assets folder
}
catch
{
throw new Exception("Error when trying to save file to Assets folder.");
}
// ... bunch of other stuff
return View();
}
模型是这样的
@using (Html.BeginForm("Index",
"FileUpload",
FormMethod.Post,
new { enctype = "multipart/form-data", @id ="upload-file-form"}))
{
<div>
<label for="file">Upload File:</label>
<input type="file" name="file" id="file" /><br>
<input type="submit" value="Upload" /><img class="loading-icon hidden" src="/ClientPortal/images/loadinggif.gif"/>
<input type="hidden" name="selectedOrgName" class="selectedOrgInput" />
<input type="hidden" name="selectedCatName" id="selectedCatInput"/>
<input type="hidden" name="previouslyUploadedFilesJSON" value="@ViewBag.uploadedFilesJSON" />
<br><br>
</div>
}
我想知道的是,我是否有可能在客户端有一个与saveAs 函数的进度相关联的进度条。在谷歌浏览器中,浏览器窗口底部已经有一些东西,比如
Uploading (31%)
上传文件时,必须有某种方式在客户端接入该号码,或者必须有其他方式使用控制器。
【问题讨论】:
-
我愿意打赌谷歌没有使用 HttpPostedFileBase ;-)。我猜他们正在使用AJAX?查看this link。
-
是要报告saveAs的进度还是文件上传的进度?
-
@bmm6o 文件上传
标签: javascript c# asp.net asp.net-mvc razor