json - Returning complex KO ViewModel to controller -


I tried to follow this post here, but it was a bit intolerable.

I have a ViewModel when I dump JSON as a model on this page so it looks like this:

  {"selectedCatalog": 7, " Catalog ": [{" name ":" EDI outbound "," list id ": true," gross ": true}, {" name ":", "" truth "," total ": true}, {" name ":" Active "," active "," active "," adwords "," active "," active "," active "," active "," active " "PdbColumnId": 2, "selectedColumn": 2}, {"pdbColumnName": "category", "outbound columnname": "category", "PDB column ID "PdbColumnName": "Inventory", "Outbound columnname": "Inventory", "PDB column ID": 4, "Selected column": 4}, {"pdbColumnName "," Manufacturer "," Outbound columnname ":" Manufacturer "," pdbColumnId ": 5," selectedColumn ": 5}, {" pdbColumnName ":" "MSRP", "PDB column ID": 7, "Selected column" : "", "Output column name": "", "Outbound columnname": "," "name", "Outbound column": 6, "Selected column": 6}, {"PDB columnname": "Manufacturer SKU", "Outbound columnname", "PDB column ID" Column name ":" name "," PDB column occurred "", "Selected column": 8}, {"pdbColumnName": "value", "outbound columnname": "value", "pdbColumnId": 9, "selected column": 9}, {"pdbColumnName": "SKU", "Output columnname": "SKU", "pdbColumnId": 10, "Selected column": 10}, {"pdbColumnName": "" "" Weight "," PDB column ID ": 12," Selected column ": 12}]}   

I'm not sure how it works with my controller. I am able to post back but the string is empty from: Controller

  [http post] Public Zero UpdateCatalog (string data) {var heh = data; }   

see

  function catalog configurationmodel (data) {var self = this; Self.pdbColumnName = ko.observable (data.PDBColumnName); Self.outboundColumnName = ko.observable (data.OutboundColumnName); Self.pdbColumnId = ko.observable (data.PDBColumnId); Self.selectedColumn = ko.observable (data.ConfiguredColumnId); } Function list list (data) {var self = this; self.name = ko.observable (data.Name); self.catalogId = ko.observable (data.Id); self.enabled = ko.observable (Data. enabled); Self.aggregate = ko.observable (data.Aggregate); } var ViewModel = function () {var self = this; Self.submitChanges = function () {var data = ko.toJS (ViewModel); $ .post ('/ PDBConfig / UpdateCatalog /', data, function (status) {warning (status);}); }; //self.catalogs = ko.observableArray ([// new list list ('EDI outbound', 2, 1), // new catalog list ('CSV outbound', 1, 1) //]); self.selectedCatalog = ko.observable (); self.catalog = ko.observableArray ([]); Self.catalogconfiguration = Co.obsbian Array ([]); $ .getJSON ("/ PDBConfig / GetCatalogList /", function (data) {var mapped tasks = $ .map (data, function (items) {new list list (item)}); self-inventory (mapped work ); Self Selection List (self.catalogs [1]); $ .getJSON ("/ PDBConfig / GetCatalogConfig /", {id: data [0]. Idid}, function (catalogs) {var mapped list = $ .map (list data, function (item) {new catalog configuration model (item)}) own listing (mapped list);});}); }; $ (Document) .ready (function () {var model = new ViewModel (); model.selectedCatalog.subscribe (function (newValue) {$ .getJSON ("/ PDBConfig / GetCatalogConfig /", {id: newValue}, function ( CatalogData) {var mapped list = $ .map (list data, function (item) {new catalog configuration model (item)}); model listing (mapped);});}); co.applyindings (model) ;   

The question is, where should I begin to map it to C #? Should I make a model with the same naming convention in my JSON string?

< Div class = "post-text" itemprop = "text">

To start, if you pass it to your controller as a string, then all this is actually. Newtonsoft JSonNet Convertor () We Use the framework to handle these conversions.

With this library, you can pass the string directly into your object such as:

  [http post] public Jasonnet Result Updates (updatedcodelmodel data) {.. ..}   

You can also use

If you have any questions about the implementation of the library, go to the SO group:

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -