3

我有一个委托方法,在 WritingAnObject 上传文件时称为周期性。我想用 args.PercentDone 值更新我的 MVC 页面中的 div (ProgressUpdate)。我很感激任何想法?谢谢,

//委托方法

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

//控制器

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

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

//看法

<%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”&lt;/div>
4

1 回答 1

0

这是您可以在服务器上的操作完成时向用户显示进度的一种方法。(需要javascript)

1) 编写一个在服务器上启动进程的动作。此方法应更新会话状态中的进度值(使其特定于用户正在运行的每个会话)。

2)编写一个客户端可以调用以返回进度的操作。这将读取会话状态中的值。通常,此操作将返回包含填充到正确数量的进度条的小 HTML 片段,或包含进度值的 JSON 对象。

3) 从您的客户端,进行 jQuery.ajax() 调用以在操作运行时异步轮询服务器以获取进度并更新 UI。

额外的花里胡哨: - 取消长时间运行的操作的操作 - 在 Web 应用程序之外运行任务(Azure 有一些关于从 Web 应用程序异步运行任务的出色功能) - 让返回进度的操作也让客户端知道操作是否已完成或取消。

于 2011-02-18T19:18:50.883 回答