asp.net mvc - How to return status information during lengthy batch process in MVC 4 action? -
in mvc 4 app, have view uploads file client machine with:
<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>
the "batch" action in home controller takes file , processes in way may lengthy.... minutes even:
<snip> [httppost] public fileresult batch(modeltype modelinstance) { // 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>
this works fine, , isn't inherent problem user locked out time takes batch process run. in fact expect it. problem user may not in position know whether process take couple of seconds or couple of minutes, , provide them status information while lengthybatchprocess running. have researched unobtrusive ajax, not seem have functionality necessary this, unless there way chain unobtrusive ajax calls. thoughts on how best architect this? many in advance.
what want achieve requires bit of work.
one way open channel (ajax call) progress report. quoting how measure progress of web service call?:
write separate method on server can query passing id of job has been scheduled , returns approximate value between 0-100 (or 0.0 , 1.0, or whatever) of how far along is.
i've found a great tutorial on matter.
Comments
Post a Comment