在我的MVC 4应用程序,我有一个从客户端计算机上传文件,以期:如何在MVC 4操作中的漫长批处理过程中返回状态信息?
<snip>
@using (Html.BeginForm("Batch", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input class="full-width" type="file" name="BatchFile" id="BatchFile"
<input type="submit" value="Do It" />
}
<snip>
在家里控制器的“批量”操作需要该文件,并在某种程度上可能会对其进行处理非常漫长....分钟连:
<snip>
[HttpPost]
public FileResult Batch(ModelType modelInstance)
{
// Do the batch work.
string result = LengthyBatchProcess(modelInstance.BatchFile.InputStream)
var encoding = new ASCIIEncoding();
Byte[] byteArray = encoding.GetBytes(result);
Response.AddHeader("Content-Disposition", "attachment;filename=download.csv");
return File(byteArray, "application/csv");
}
<snip>
这一切工作正常,这是不是用户被锁定为它花费的批处理进程运行时的固有问题。事实上,他们期望它。问题是用户可能无法知道这个过程是需要几秒钟还是几分钟的时间,并且我想在运行LongyBatchProcess时向他们提供状态信息。我研究了不引人注目的ajax,但它似乎没有必要的功能,除非有某种方法可以链接不显眼的ajax调用。关于如何最好地设计这个的任何想法?提前谢谢了。
教程看起来不错,我迫不及待地想尝试一下。谢谢。 – 2013-05-13 01:39:19