I have been following a pluralsight course in an attempt to learn how Client Side View Models can interact with server side controller actions.
I have a basic view model with a couple of string properties. Using knockout and knockout mapping I can successfully map my server view model to the client side view model, make changes in the view and call a save method that calls back to my Controller’s Save action.
The flow all works nicely, except that the JSON sent to the Save action is not deserializing to create the server side view model that is the parameter taken for the Save action.
In the sample code I have from the Pluralsight course, break points in the View Model show me the property setters are all called when the Save action is called from the client. (This doesn’t occur on my View Model class.)
I have tried many things, mostly from suggestions here on Stack Overflow:
- Various attributes on the Save action’s parameter – like (FromBody) etc.
- Combinations of toJSON, toJS, etc in the AJAX call
- I have shown the content of the client side object using alter() and also in the Chrome Developer windows does contain what I expect.
- Break points show the server side object being created when the Save action is called but no properties are set.
I feel this could be caused by discrepancies between ASP.Net Core (my project) and the sample course that uses .Net 4.5, or slightly different version of knockout.js (as I’m not sure how to include the same versions of those files using VS2019’s Add Client Side library tool (all references I’ve found refer only to the “Bower” tool which has been deprecated.)
Can someone suggest what differences I am facing with ASP.Net Core that could be preventing the deserializing on the controller action call from the client?