Reputation: 1036
I have a form with input controls wired to a javascript viewmodel using Knockoutjs. However after clicking on the submit button all the values in it are lost. Is there any way to persist this temporary data between postbacks by using say hidden fields?
Upvotes: 2
Views: 3341
Reputation: 1045
Knockout being a good framework does not have features like data persistence, URL history etc. However you have a lots of plugins that provides these functionality. Check out
https://github.com/jimrhoskins/knockout.localStorage
https://github.com/katowulf/knockout-sync
There can be many more. Try one that suits your app.
Upvotes: 4
Reputation: 11
Actually you can save state in a hidden field. Take a look at this http://www.codeproject.com/Articles/153735/Using-KnockoutJS-in-your-ASP-NET-applications.
Upvotes: 1
Reputation: 15984
If you refresh the page on postback all js state is lost. That is unless you use cookies or local storage to store state and retrieve on next load. Hidden fields get destroyed on postback so they won't help you i'm afraid.
If you have have your form bound to a viewModel using KO, why not submit it via ajax and don't refresh the page. This is really where KO shines and allows you to build much more responsive applications.
Hope this helps.
Upvotes: 2