views:

195

answers:

1

Does ASP.NET MVC provide any way to implement UpdateProgress WebForms control analog? Can anyone explain me how to achieve such client-side functionality with MVC?

+2  A: 

Using a little jQuery and AJAX makes it pretty easy (or complex, if you want to do something hard) to do this. This little snippet updates a DIV from a method that renders a partial view to HTML. It first replaces the current contents with a loading message, then updates the DIV with the response from the server by overwriting the loading message when the data is returned. You can do other things like showing an animated GIF or get really complex and set up an interval timer to periodically check the status of a long running activity and do a progress meter. Obviously, the latter is much more complex.

 $('#myButton').click( function() {
      $('#myDiv').html('Please wait while the data is loaded.');
      $.ajax({
         url: '<%= Url.Action( "action" ) %>',
         data: $('form').serialize(),
         type: 'post',
         dataType: 'html',
         success: function(data,status) {
             $('#myDiv').html( data );
         }
      });
 });
tvanfosson