c# - MVC JsonResult updating progress -


mvc 4 webapp, jquery

i want show progress of lenghty procedure.

the following gets called json takes several seconds...

basically, is:

[httppost] public jsonresult update(var x) {     return json(new { result = "working", message = "waiting on server" });     var y = contactanotherserver(x);     return json(new { result = "working", message = "crunching data" });     var finished = dosomethingwithdata(y);     return json(new { result = "ok", message = "done" }); }  

obviously terminate on first return-statement.

how done ?

thank you!

to "roll own" this, need 3 separate jsonresult methods , complex javascript function. ie:

controller

public jsonresult step1() {     return json(new { result = "working", message = "waiting on server" }); } public jsonresult step2() {     return json(new { result = "working", message = "crunching data" }); } public jsonresult step3() {     return json(new { result = "ok", message = "done" }); } 

js

// urls var urls = ["/step1","/step2","/step3"];  // counter var counter = 0;  // recursive method var fetchandupdaterecursive(url){     // data    $.ajax(url, {         async: false,         success: function(r){                // use r update visually               // then...                // change url               counter++;               url = urls[counter];                // go again               fetchandupdaterecursive(url);         };    }); };  // go var urltostartwith = urls[counter]; fetchandupdaterecursive(urltostartwith); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -