Please wait page in ASP.NET MVC

前端 未结 5 767
北恋
北恋 2021-02-04 20:26

A page executes a number of tasks and takes a long time to process. We want to give the user feedback as each task is completed.

In ASP.NET webforms we used Respo

相关标签:
5条回答
  • 2021-02-04 21:17

    I would suggest to use AJAX for displaying progress. See links for ideas:

    • Real-Time Progress Bar With ASP.NET AJAX
    • Using jQuery Plugins with ASP.NET
    • Ajax Progress Bar Control
    0 讨论(0)
  • 2021-02-04 21:21

    You can make it in client side. In each step, you set some session variable with the current step. Then, You make another action in your controller say called: "GetProgress" and assign a view and URI for it.

    In the action, you will check this session and return the current progress of your task. In the client side, make a timer (i.e setTimeOut) and you invoke the URI of the later controller action every specific amount of time - 1 second or so. That is it.

    0 讨论(0)
  • 2021-02-04 21:29

    There are two basic ways:

    1. Poll a server page that returns the status, then once the operation is done, redirects to a results page. MVC is nothing to do with this way, you'd need to use a server variable to store objects/status - this is a way that's more relevant to a standard Asp.NET application as you're (presumably) using session variables etc. anyway.

    2. AJAX call from the client to a webservice on the server. Asp.NET MVC is going to be rolling the jQuery framework in, so use that for the client call and event handling for the response. This would be more in the spirit of MVC which doesn't/shouldn't use session state etc.

    0 讨论(0)
  • 2021-02-04 21:30

    You can still use Response.Write() and Response.Flush() for whatever status you want to send down the wire. Or if you have your progress thingy in a user-control, you could do something like:

    this.PartialView("Progress").ExecuteResult(this.ControllerContext);
    this.Response.Flush();
    

    from your controller while doing your lengthy operation in the controller's action method.

    It's up to you to choose this or the client-side approach as mentioned in the comments here, just wanted to point out that server-side is still possible.

    0 讨论(0)
  • 2021-02-04 21:33

    Me personally I would consider two optoins:

    • redirect to wait page(s), then fire actions
    • Do it ajax style
    0 讨论(0)
提交回复
热议问题