0

I am trying to build a page with three cascading dropdowns, lets say Brand, Model and Year, which is rather easy using something like Knockoutjs.

The thing is that I'd like to keep state in the querystring, so while making my choices, the URL is being updated also to something like '/Cars?Brand=Toyota' etc. (if the browser supports it).

Furthermore, if the users hits '/Cars?Brand=Toyota&Model=Corolla', I'd like the dropdowns to reflect that state.

At first I thought that something like this would be trivial with Knockoutjs, but is seems that it's not.

So, is there a way to 'bind' to querystring parameters using Knockoutjs? If not, is this something that can be done using a framework like Angular?

lalibi
  • 3,057
  • 3
  • 33
  • 41

1 Answers1

0

The easiest way would to just bind the values to your view model and then use jquery to update the querystring when the values change.

Updating existing URL querystring values with jQuery

If you then wanted to be really clever then i imagine you could move this code into a custom binding extension.

http://knockoutjs.com/documentation/custom-bindings.html

Community
  • 1
  • 1
4imble
  • 13,979
  • 15
  • 70
  • 125