我有一個使用RAZOR視圖的vb.net MVC3應用程序。一些功能需要很長時間才能完成,因爲它們正在編譯數據庫中的數據。在這漫長的等待期間,瀏覽器屏幕是白色的,並且沒有跡象表明它正在做什麼而不是活動環。我想要做的是創建一個進度條,在count方法上使用一些簡單的數學來確定進度條完成百分比,並在屏幕上顯示它,而不是純白色的瀏覽器屏幕。我確信我需要使用某種類型的Jquery小部件來做到這一點。而且到處都找過谷歌,但似乎沒有任何要什麼我需要在這裏打..當顯示白屏,直到它完成時調用的控制器功能低於:如何從控制器創建進度條以處理MVC3中的長進程
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視圖是這個:
@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>
如何,我會去加入一個簡單的進度條,這裏面我假設都必須由控制器本身被解僱任何想法...
我可以只是有beginArchive返回成功,而不是使用重定向? – Skindeep2366 2012-08-06 02:25:15
你可以在jQuery post調用的函數回調中做任何你想做的事情。如果你想顯示一條消息,並在成功時保持在同一頁面上,只需將'window.location'行替換爲其他內容即可。 – 2012-08-06 02:28:02
對不起,如果我假設jQuery/JavaScript知識作爲我的答案的一部分。但據我所知,這是處理這個問題的好方法。 – 2012-08-06 02:29:16