开发者

How to pass progress to MVC page

开发者 https://www.devze.com 2023-01-18 17:15 出处:网络
I have a delegate method with is called periodic while WritingAnObject uploading the file.I would like to update开发者_如何学JAVA div (ProgressUpdate) in my MVC page with args.PercentDone value. I app

I have a delegate method with is called periodic while WritingAnObject uploading the file. I would like to update开发者_如何学JAVA div (ProgressUpdate) in my MVC page with args.PercentDone value. I appreciate any idea? Thanks,

//delegate method

private void displayProgress(object sender, ProgressArgs args)
{
            //Console.WriteLine(args.PercentDone); //I want to display args.PercentDone in the page
}

//Controller

[HttpPost]
public ActionResult WritingAnObject(MyViewModel bovModel)
{
    //DoSomeStuff which is cause calling displayProgress

    return RedirectToAction("ListingSomeInfo", "testpart");
}

//View

<%using (Html.BeginForm("WritingAnObject", "testpart", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {%>   

    <%:Html.TextBox("catname") %>
    <input type="file" id="fileupload" name="fileupload" />
    <input type="submit" value="Upload" />
    <%} %>


<div id= “ProgressUpdate”</div>


Here is one approach you could take to display progress back to a user while an operaton on the server is completing. (requires javascript)

1) Write an action that starts the process on the server. This method should update a progress value in session state (so that it is specific to each session the user is running).

2) Write an action that the client can call to return progress. This would read the value in session state. Generally this action will return either a small HTML fragment containing the progress bar filled in to the right amount, or a JSON object containing the progress value.

3) From your client, make a jQuery.ajax() call to asynchronously poll the server for progress while the operation is running and update the UI.

Additional bells&whistles: - an Action to cancel a long running operation - running the task outside the web application (Azure has some excellent features regarding running tasks asynchronously from a web app) - Have the action that returns progress also let the client know if the operation is completed or canceled.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号