[英]Communicate progress between server and client
I have a controller action which imports an uploaded excel file into a database. 我有一个控制器操作,它将上载的excel文件导入数据库。 The import can take several minutes.
导入可能需要几分钟。 How can I report the progress of the import to the client?
如何向客户报告导入进度? I know that I have to use ajax but I could not find any clean code which would be ideal to report a progress.
我知道我必须使用ajax,但找不到任何理想的报告进度的干净代码。
I am quite new to mvc4 and asp.net. 我对mvc4和asp.net相当陌生。 So I would like to hear your advices/approaches to solve my problem.
因此,我想听听您的建议/方法来解决我的问题。 I would like to write a solid and clean solution but I really don't know how to start.
我想写一个可靠的解决方案,但我真的不知道如何开始。
Would be very nice if anyone would have any experience in reporting the progress to the client. 如果有人在向客户报告进度方面有任何经验,那就太好了。
A simple method is to have the upload method (which begins the processing) return an ID for the job that is running. 一种简单的方法是使upload方法(开始处理)返回正在运行的作业的ID。 Then query the job status using that ID.
然后使用该ID查询作业状态。
I would strongly suggest to use plupload plugin. 我强烈建议使用plupload插件。 This plugin It works perfectly for all browsers and have progress bar
该插件对所有浏览器都完美运行,并具有进度条
If you are importing the data into MSSQL via a job, you can use a script to monitor the status of the job until it is complete. 如果要通过作业将数据导入MSSQL,则可以使用脚本来监视作业的状态,直到完成为止。 If the client needs to know the % of record imported, you could retrieve the number of rows to be imported from the excel sheet and compare it to the total rows in the table.
如果客户需要知道导入记录的百分比,则可以从excel工作表中检索要导入的行数,并将其与表中的总行进行比较。 You can then report back the percent of rows that have been imported.
然后,您可以报告已导入的行的百分比。
However, this can get tricky if it is not a simple import into a table, but multiple tables. 但是,如果这不是简单地导入到一个表中而是多个表,则可能会变得棘手。 In that case it would be up to you to figure out the expected number of rows added and monitor all of those against the current import.
在这种情况下,您将需要确定预期添加的行数,并根据当前导入监视所有这些行。
Once you figure that out, it wouldn't be too hard to supply a status bar back to the user based on the data returned. 一旦弄清楚了,就可以根据返回的数据向用户提供状态栏,这并不难。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.