0

On the controller side I download a file and loop each line on the file and sending request to server by Web API.

I want that each return request answer will update the view progress bar percentage.

What is the best practice to update the view progress bar if all the operation is done on the IActionResult and return to view after all file operation finished:

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
liron
  • 57
  • 6

1 Answers1

0

A Progress Bar is used to show the progress of a task, so probably your task is number of file's lines.

from here you can determine number of lines : https://stackoverflow.com/questions/119559/determine-the-number-of-lines-within-a-text-file#:~:text=IO.-,File.,to%20know%20how%20many%20lines.

now that you have this, you can define a counter that after end of each loop increase by one.

//set initial value to 0

lineCounter += 1;

Progress Bar Action:

public ActionResult UpdateProgressBar(int lineCounter, int allLines)
{
    var current_Progress_value = (lineCounter/allLines)*100;
    //Pass the value to view
    ViewBag.curr_value = current_Progress_value;
    return View();
}

like above you can pass the value to the view with "viewbag" in your controller.

and in your view:

@{
     var ProgressValue = (int)ViewBag.curr_value ;
}

here is ProgressBar html code:

<div class="progress">  
    <div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="@ProgressValue" aria-valuemin="0" aria-valuemax="100" id="lblStatus">
    </div>  
</div> 

hope this be right, works and help you.

Moharouki
  • 11
  • 1