Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MVC, WebAPI Controllers and LocalStorage
Message
De
03/07/2014 11:13:42
 
 
À
03/07/2014 10:45:45
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:
01603186
Vues:
43
>>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?
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