简体   繁体   中英

Communicate progress between server and client

I have a controller action which imports an uploaded excel file into a database. 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.

I am quite new to mvc4 and 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. Then query the job status using that ID.

I would strongly suggest to use plupload plugin. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM