Click here to Skip to main content
13,198,322 members (66,348 online)
Rate this:
Please Sign up or sign in to 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:
 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...
@using ViewModel
   <h2>My View</h2>
   <p> some data here </p>
   <div id="mypartialView">
   @{html.Renderpartial("_results", Model.Results);}

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

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can start with something like this one:[^], or this one:[^].

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:[^]

Good luck!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171020.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100