I have a vb.net MVC3 application using RAZOR views. Some of the functions take a long time to complete due to the fact that they are compiling data from the database. During this long wait the browser screen is white and there is no sign that it is doing whats its supposed to other than the activity ring. What I would like to do is create a progress bar, use some simple math on the count method to determine the progress bar percent complete and show this on the screen instead of the plain white browser screen.. I am certain that I would need to do this with a Jquery widget of some sort. And have looked all over google but nothing seems to be hitting on what I am needing here.. The controller function that is called when the White screen is displayed until it is finished is below:
Function beginArchive()
Dim cList As List(Of cours) = db.courses.ToList
For Each x In cList
Dim indCourse = x
Dim courHfile As String = archiveFiles(x.course_id)
Dim arcCourse As New archive
arcCourse.cDesc = indCourse.course_description
If Not String.IsNullOrEmpty(courHfile) Then
arcCourse.cHandouts = courHfile
End If
arcCourse.cHours = indCourse.course_hours
arcCourse.conNum = Convert.ToInt16(indCourse.courseNum)
arcCourse.cPre = indCourse.course_prefix
arcCourse.cRef = indCourse.course_ref
arcCourse.cSpeaker = indCourse.course_speaker
arcCourse.cTitle = indCourse.course_title
db.archives.AddObject(arcCourse)
db.SaveChanges()
Dim testSuccess As Integer = delOldFiles(indCourse.course_id)
Next
Return RedirectToAction("Index", "Admin")
End Function
Razor View is this:
@Code
ViewData("Title") = "Archive Previous Conf. Handouts"
End Code
<fieldset>
<h2>You are about to archive all handouts from last years conference. If you continue all of those handouts will be moved to the archive</h2>
<div id="sidebar3">
<p>
@Html.ActionLink("Begin Archive", "beginArchive","handoutArchive")
@Html.ActionLink("Back to Admin Tools", "Index", "Admin")
</p>
</div>
</fieldset>
Any ideas on how I would go about adding a simple progress bar to this which I am assuming would have to be fired by the controller itself…
What you are essentially asking for cannot be achieved with the current design of your page/actions. You are clicking a link that makes a request to your controller. The controller is going to wait until the action is finished before rendering and returning a response. This is different than making an ajax call which would return the data to the current page instead of directing you to a new url. There are many ways to do this, and a lot of them depend on your requirements for how you want it to work.
If it was me, and I was trying to do a large operation, This is what I would do.
Display a spinner or some sort of icon with a message saying “this could take awhile” and make an ajax request to your action. When the action returns you can display a message or redirect to a new route.
An example using jquery
This assumes that your
beginArchivemethod returns json like{"status":"success"}or{"status":"error archiving reason blah"}(I’m a c# guy so apologies if the vb.net is not right, it’s just an example of how I envision the implementation of the action).
Unfortunately, without knowing more about what your implementation of “archiving handouts” is, I can’t really tell you a good solution for showing the progress of the action would be. But I feel like this is a standard solution that many applications use when processing intensive operations.