jquery - WebAPI - Passing JSON of derived class -
i using kendo ui,entity framework, , angularjs , trying serialize derived class type in kendo grid , send webapi method. have follow model association:
class freq_pool<---- base class class pool_faa:freq_pool<----derived class class frequency(contains freq_pool object)
i using kendo ui model follows:
model: { id: "id", fields: { frequency: { type: "string" }, freq_pool: { $type: 'domainmodelmodule.pool_faa, domainmodelmodule', // type: "object", defaultvalue: {} } } } .... $("#faafreqgrid").kendogrid({ datasource: faads, columns: [ { field: "frequency", editor: categorydropdowneditor, title: "frequency test", format: "{0:c}", width: "120px" }, { field: "freq_pool.faadesignator", title: "faa designator", format: "{0:c}", width: "120px" },
faadesignator belongs derived class pool_faa. works 100% fine when have manually created row in db. creation part in code not working.
i using right typename handling in web api config based on have read:
var json = config.formatters.jsonformatter; json.serializersettings.preservereferenceshandling = newtonsoft.json.preservereferenceshandling.objects; json.serializersettings.referenceloophandling = referenceloophandling.ignore; json.serializersettings.typenamehandling = typenamehandling.auto; //this needed casting json.serializersettings.typenameassemblyformat = system.runtime.serialization.formatters.formatterassemblystyle.full; config.formatters.remove(config.formatters.xmlformatter);
now still unable cast freq_pool pool_faa in webapi method:
[responsetype(typeof(frequency))] public ihttpactionresult postfrequency([frombody]frequency testfreq) { frequency ftest = new frequency(); ftest.freq_pool = new pool_faa(); pool_faa sdgsdg = (pool_faa)ftest.freq_pool;//works when manually created pool_faa pool = (pool_faa)testfreq.freq_pool;//throws exception }
as saw, used $type establish type should cast to, not seem working.
i noticed $type not appearing in stringified json:
{"id":0,"frequency":"","freq_pool":{"faadesignator":"sdfgsfdg","datefilled":"dfg","duedate":"fhg","released":"sdfh","releaseddate":"dsfh","comments":"sdfh"},
but including don't know why excluding it. best guess why isn't working. using angular , kendo, , since variable inside kendo model thought might excluding $type or something.
any ideas? thanks.
when switched model-first code-first, didn't explicitly use tpt inheritance. after switching tpt tph inheritance solved.
Comments
Post a Comment