Search code examples
jsonasp.net-mvc-2dotnetnukemodel-binding

How can I get DotNetNuke 6.2 Service Framework to modelbind json data


DotNetNuke Serviceframework is based on ASP.NET MVC 2, and therefore does not include json modelbinding out of the box.

I've tried a number of approaches:

  • MVC3 jsonvalueprovider
  • custom json model binder
  • custom value provider

The code to register these was called, however the methods on these objects themselves were not called.

Registering these is an interesting area in itself as in DotNetNuke, we don't have access to the global.asax file.

I've also attempted to deserialize the request input stream, in the the controller, but I get a nullreferenceexception there, and I get the correct data size, but all nulls!

Any ideas?!


Solution

  • Ok,

    I have a workaround that is clean and functional.

    I'm using a jquery plugin from here .This converts json into a standard forms form post for you. using this with jquery & knockout looks like this:

     $.ajax({ 
           url: '<%= ModulePath %>Api/Register/Search', 
           type: 'POST',  
           data: $.toDictionary(ko.mapping.toJS($root),"",true), 
           success: function (data) { //do something });
    

    Leaving the question open, in case anyone has any ideas to get json working directly.