Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MVC, WebAPI Controllers and LocalStorage
Message
De
03/07/2014 12:11:48
 
 
À
03/07/2014 11:22:46
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8
Network:
Novell 6.x
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01603183
Message ID:
01603192
Vues:
32
>>>>Hi,
>>>>
>>>>I am starting to work on using Local Storage for my ASP.NET MVC/Web API application.
>>>>
>>>>The application allows a user when in the office to select the run sheet (list of packages to be delivered) and then a copy of all the data for that run sheet gets stored in the local storage of the browser. The user then delivers all the packages, recording the deliveries in local storage and upon returning to the office all the deliveries are transferred from local storage to the database on the server. Or at least that is how it is supposed to work. :)
>>>>
>>>>My problem is that I am getting all the run sheet details from the database and displaying them no problem the first time using his code:
>>>>
>>>>
        public ActionResult Index(Guid id)
>>>>        {
>>>>            RunSheetDetailsListViewModel vm = new RunSheetDetailsListViewModel();
>>>>            var query = this._unit.RunSheetDetails.GetByRunSheetId(id); //.GetAll().OrderBy(rnh => rnh.Route.rte_name);
>>>>            vm.RunSheetDetails = query.ToList();
>>>>
>>>>            return View("Index", vm);
>>>>        }
>>>>
>>>>
>>>>In my Index.cshtml I have this:
>>>>
>>>>
            var vm = new ViewModel();
>>>>
>>>>            var serialized = JSON.stringify(vm.runSheetDetails());
>>>>
>>>>            runsheetdetailsDataService.saveLocal(serialized);
>>>>
>>>>in the jquery ready function.
>>>>
>>>>This apparently saves the data properly in the local storage.
>>>>
>>>>Now, when the user is not connected to the server, how do I tell the Index ActionResult to pull the data from local storage rather than the database?
>>>
>>>Not familiar with the .saveLocal() method. I just save directly to a key:
localStorage['theData'] = JSON.stringify(vm.runSheetDetails); // Store
>>>vm.runSheetDetails = JSON.parse(localStorage['theData']); // Retrieve
Don't know if that would work for you. You could look in the Browser debugger to discover the key that was used by 'runsheetdetailsDataService.saveLocal(serialized)'
>>
>>My saveLocal() basically does the same thing, saving to a key. But that's not the problem, the problem is how do I tell the page/view/controller/model to pull the data from the local storage not from the database? Do I need to detect in my view that we are offline and then load another page which ignores the MVC model and just loads it from local storage? Or is there another way?
>
>You can check the navigator.online property to determine if there's a connection (but that's no guarantee that you can access (a) the internet and (b) your server)
>
>If I have a page that must sometimes operate offline then I tend to design it as if that were the normal case and have 'Refresh Data' and 'Upload' buttons that are only enabled when navigator.online is true.
>
>I assume you know that you will need an offline manifest for the page ?

The example I have been following has a way of polling for a file on the server and if not found then the app "runs in offline mode", but it doesn't do anything like what I am trying to do which is display a list of data that is stored locally if that data is found, otherwise, if it is on-line, then get the data from the database and store it locally. I know about the manifest files and so on.

I think I'm going to have to display a page showing the local data and avoiding the MVC stuff for now when it detects it is off-line.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform