Click here to Skip to main content
15,895,813 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have an MVC 3 application (A) which allows multiple clients to process data forms - for example a survey form. There is an external process (B) to which the survey forms are sent. The external process (B) then figures out how many clients are working to process these survey forms (there may be thousands of surveys) and distributes as many of the the current set of surveys to each client (where each client can hold a fixed number of surveys) such that when the client logs into the main application (A) he will log into the processing application and that client will be shown a subset of the unprocessed forms which he/she can then select to work on. When the client has chosen one or more items to work on from the list, those items are removed from the list. There may not be enough clients at any given time to fullfill all of the outstanding unprocessed surveys, but the external process re-distributes the surveys to the current set of logged on clients every refresh interval (say 15 minutes.)

Now, say more clients log on to get some of these items to work on; this causes the Process (B) to redistribute the unprocessed survey forms to all current active (logged in) clients.
The problem:

when the client logs in he will see a list of surveys that he can work on. However, if he does not process all of the displayed surveys in the 15 minute period following his logging in, then the external process (B) will have redistributed the surveys so that what he currently sees on his screen my no longer be accurate. All he has to do is to refresh his page and he'll get the latest set. But I'd like him to not have to refresh but rather I'd like to have the external process (B) send an event that would cause the partial view which shows the client's list of surveys to update with the latest view.

I have been searching for a way to do this but so far haven't come up with any ideas.

The data that needs updated is in a partial view so if I could subscribe to some kind of event then when the process (B) had new data it could fire this event and I could pick it up.

In this situation the entire application is an intranet application so the service and the clients are in the same building and are all inside the firewall.

What I would like to be able to do is something like this:
C#
 public myController
{
   public ActionResult Index()
   {
        // get list of my surveys
        var results = MyRepository.GetNewSurveys();

        // add to the view model
        var viewModel = new ViewModel() { Results = results};

        // somehow subscribe to some kind of event

        return View(viewModel);
        // return a view
   }

   public void SomeEventHandler()
   {
         // update partial view that is inside the Index View's cshtml with the updated list
   }


Index.cshtml here...
C#
@using ViewModel
<div>
   <h2>My View</h2>
   <p> some data here </p>
   <div id="mypartialView">
   @{html.Renderpartial("_results", Model.Results);}
   </div>
</div>



Thanks in advance
Posted
Comments
Zoltán Zörgő 15-Sep-12 4:52am    
Any progress?

1 solution

You can start with something like this one: http://mazharkaunain.blogspot.hu/2011/05/aspnet-mvc-razor-render-partial-view.html[^], or this one: http://geekswithblogs.net/blachniet/archive/2011/08/03/updating-partial-views-with-unobtrusive-ajax-in-mvc-3.aspx[^].

I would add a little ajax callback in the page. The backend would check if the data is changed, and if it was changed, it would return a specific message, that can be handled by the page to reload the partial view. This callback could be called in every x seconds. But be aware, this might be a heavy load if there are many clients, thus you have to guess this interval properly. I would also play around with http 1.1 keep-alive also on server side.

I know of no other all-around supported way of having the server send out events to the browser. In html5 you have an api for that, but I don't know about it's support: http://html5doctor.com/server-sent-events/[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900