Thursday, 15 March 2012

c# - MVC3 Async jQuery progress bar on a insert query -



c# - MVC3 Async jQuery progress bar on a insert query -

so trying add together async progress bar on slow , long query inserts bunch of rows database. implementation based off example: http://blog.janjonas.net/2012-01-02/asp_net-mvc_3-async-jquery-progress-indicator-long-running-tasks

here javascript code progress bar

function updatemonitor(taskid, status) { $("#" + taskid).html("task [" + taskid + "]: " + status); } //other code if (dosend == true) { $.post("/sendbatch/handlebatchrequest", { //other code }, function (taskid) { // init monitors //breakpoint here not stop it, never enters somehow? $("#monitors").append($("<p id='" + taskid + "'/>")); updatemonitor(taskid, "started"); // periodically update monitors var intervalid = setinterval(function () { $.post("sendbatch/progress", { id: taskid }, function (progress) { if (progress >= 100) { updatemonitor(taskid, "completed"); clearinterval(intervalid); } else { updatemonitor(taskid, progress + "%"); } }); }, 100); } ,"html");

then there div within display part of website

<div id="monitors"></div>

here how controller looks

public sendbatchcontroller //some code private static idictionary<guid, int> tasks = new dictionary<guid, int>(); public actionresult handlebatchrequest( //some code ) { var taskid = guid.newguid(); tasks.add(taskid, 0); var batchid = guid.newguid().tostring("n"); var costd = cost.todecimal(); ienumerable<batchlistmodel> customers; seek { customers = new customerservice(_customerrepository.session).getcustomers( //some code ); } grab (exception err) { homecoming json(err.message); } if (dosend) { var sent = 0; foreach (var c in customers) { seek { var usr = _customerrepository.loadbyid(c.id); var message = new comlog { //insertions log }; _comlogrepository.save(message); sent++; //progress bar part within here of import comes here: tasks[taskid] = sent; } grab (exception e) { log.writeline("err:" + e); } tasks.remove(taskid); } homecoming json(taskid); } homecoming json(customers.count() + " customers"); } public actionresult progress(guid id) { homecoming json(tasks.keys.contains(id) ? tasks[id] : 100); }

this not work. process works in background. div never shows , never gives indication. know lot of code read stuck , love input on how prepare this.

try alter updatemonitor function :

function updatemonitor(taskid, status) { $("#monitors").html("task [" + taskid + "]: " + status); }

c# jquery asp.net-mvc-3 asynchronous progress

No comments:

Post a Comment