asp.net mvc 4 - How to load message in real time to a viewer in MVC 4 framework -


i'm creating mvc 4 .net/c# project data loading automatically. when insert new record database, want display line of message in viewer in real time. like

record 1 has been loaded successfully! record 2 has been loaded successfully! record 3 has been loaded successfully! record 4 has been loaded successfully! .... 

is there way this? thank idea.

of course. first @ should write method returns numer of records. on loading page can use method receive number of records f.ex:

controller:

public actionresult countrecords() {     int records = repository.countrecords();     return javascript(simplejsonserializer.serialize(records.tostring()); }  public actionresult loadrecord(int number) {     repository.loadrecord(number);     return javascript(simplejsonserializer.serialize("success"); } 

.cshtml

<script type="text/javascript"> $.ajax({         type: "post",         contenttype: "application/json; charset=utf-8",         datatype: "json",         url: "@url.action("countrecords", "controller")",         success: function (response) {             var rows = response.replace('\"', '');             (i = 1; <= rows; i++)             {                 $.ajax({                     type: "post",                     contenttype: "application/json; charset=utf-8",                     datatype: "json",                     data: i,                     url: "@url.action("loadrecord", "controller")",                     success: function (response) {                         var status = response.replace('\"', '');                         if (status == 'success')                         $('.messages').append('record ' + + ' has been loaded successfully!');                     }                 });             }         }     });     </script> 

of course take more time in 1 call controller, works. don't know if there possibility make realtime interface without calling controller many times. saving items can done same loading. regards.


Comments

Popular posts from this blog

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -

java - How to specify maven bin in eclipse maven plugin? -