In ASP: NET MVC 4 how to show how many records are being processed when uploading an Excel file?

1

I have the following question and maybe someone has already implemented it and can help me, they will see in languages like PHP I can be sending in what record it goes when I upload a file and this I'm showing via a progressbar or a message of " x records of 1200 of the file miarchivo.xls ", now in .NET MVC4 I would like to do something similar, but I do not know if I can do. To receive the file I used something like this:

[HttpPost]
public async Task<ActionResult> FileUpload(HttpPostedFileBase file) {

  if (file.ContentLength > 0) {
    var fileName = Path.GetFileName(file.FileName);
    var path = Path.Combine(Server.MapPath("~/Uploads"), fileName);
    file.SaveAs(path);
    // 1 - Por aquí proceso con EPPlus
    // 2 - Aquí elimino el archivo
  }

  return Json(new { success = true, message= "Archivo almacenado de manera exitosa"},
            JsonRequestBehavior.AllowGet);
}

The whole process of uploading, reading the file to send it to the SQL Server and the deleted one is ok, but I would like to show the user that his file is being processed, that a message of "Processing record #XXX of 14259 records (myfile.xls) " I do not know if you can do that in MVC, if you have to make any changes in the Controller or in the Entity Framework, the part of EF I'm handling with Async as well as the method.

Greetings.

    
asked by kiramishima 11.03.2016 в 23:30
source

1 answer

2

As standard asp.net mvc requires a request to the server from the client, that is, the server can not send data to the browser.

But there is an alternative if you implement SignalR

With this you could send mediate websocket data to the server informed of the actual progress of the file processing so that it reflects this in the progress.

With SignalR you would be implementing what is known as a push server, in order to send data to the browser from the web server.

Note: I do not give an example because doing so would be very extensive, analyze if this applies to what you need.

    
answered by 12.03.2016 в 00:46