asp.net mvc - Best way to pass data back to Server using Knockout.js and Viewmodel -


we have existing viewmodel has bunch of properties, has lists of enums in order populate dropdowns in view.

i noticed when using knockout.js , trying post json info back, when call:

ko.tojson(viewmodel); 

it converts all of model when sending back, including enums, not necessary when trying send server save data.

i suggested wrapping data in , doing post, there nice clean, simple way post data values without enums using knockout? best way this? should viewmodel contain enums or bad design?

check out answer similar question: https://stackoverflow.com/a/14629775/91189

yes, view model should contain data, enums, etc view needs. data post server not need contain view model's data. straightforward approach is, when you're ready send data server, construct model contains data request needs.

a different, more built-in approach expose model property on view model , bind view needed. way model pre-constructed , ready submit when are.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -