javascript - How to ensure that JS anonymous objects continue to map onto POCO ViewModels -


we have asp.net mvc application extensively uses ajax calls.

these ajax calls send data our controller method - controller method requires argument simple poco viewmodel class.

in our javascript create anonymous object properties map onto properties of our viewmodel, , mvc framework handles routing in controller method our viewmodel properties.

all , good.

what want put in place robust way ensure javascript anonymous class , viewmodel class remain in-synch - if developer changes 1 change other. can of course put in comments in both files "change one, change other", , threat of severe beating developer fails keep these in synch, code reviews area may missed.

it great have kind of automated unit test check this, i'm not aware how achieve this.

any suggestions?

thanks in advance

griff

there javascript library called knockoutjs , used trying achieve. seems trying use mvvm pattern asp.net mvc framework. mvvm pattern, it's common problem keep viewmodel in sync view. knockoutjs allows created javascript viewmodels client-side bind directly view. viewmodels updated when view updated , view updated when viewmodel updated. knockoutjs uses common pattern called observer pattern acheive this. knockoutjs provides mapping plug in viewmodels can receive server-side viewmodels in json format , update itself, updating view. functionality looking for. library , mapping plugin can found on website, www.knockoutjs.com. fyi...it producation level library. have great documentation , examples. hope helps. don't re-invent wheel.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -