1

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?!

stevenrcfox
  • 1,547
  • 1
  • 14
  • 37

2 Answers2

1

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.

stevenrcfox
  • 1,547
  • 1
  • 14
  • 37
0

You need to register a JSON value provider to get this to work. See http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx for details.

The best way to register the value provider is to do it in your route mapper. Be sure to guard the registration to ensure it occurs only once, as the route mapper is occasionally called more than once. If you are going to do this in a module deployed to servers you don't control you should probably inspect the contents of the factories collection to ensure no other service has already registered the value provider.

Services Framework in DNN 7 is based on WebAPI and natively supports JSON, so this hassle will go away soon.

ScottS
  • 8,455
  • 3
  • 30
  • 50
  • as I said in the question, I did try both using the MVC3 valueprovider, and also a custom valueprovider & valueproviderfactory. I attempted registering in the route mapper, before attempting in the httpmodule. The registration code is called correctly, however the valueprovider itself is not called... – stevenrcfox Oct 03 '12 at 09:06
  • We have used the technique I describe for several internal projects at DNN Corp. This is not just a guess, I know that it works. – ScottS Oct 03 '12 at 17:36
  • I dont doubt that it works, however I can't get it to work. Is there any other configuration/references, or known issues with 6.02.03 that could affect this? – stevenrcfox Oct 12 '12 at 09:56