value without quotes

Sep 10, 2011 at 10:30 AM

In ASP.NET MVC I often create HTML helpers to generate jquery plugin initialisation. Often these plugins arguments have events e.g.:

ScriptBuilder.Instance.JQDialog("#selector", new { autoOpen=true, title="Dialog Title", close:"function () { ... }" });

$( ".selector" ).dialog({   
   close: function(event, ui) { ... }


I would like to use fastJson to generate the argument for the dialog function, however, as you can see in the above example,
the close event has a value without quotes around it (because it is a javascript function). Any ideas how this could be done?
I know it is not part of standard json, but in this situation, it would be a great way to generate javascript server side for HTML helpers.

Note: in this example I am using a anonymous object, but  normally I would provide a DialogParams class, so the close parameter,
could be a special type , for which a custom serializer could be specified. I tried using RegisterCustomType but it emits quotes anyway.

Maybe an overloaded version of RegisterCustomeType for which the serializer delegate does not emit quotes by default?
Deserialisation is not an issue here, because, as it is used for javascript code generation, it will never be deserialised on the server... 

Jan 31, 2012 at 8:52 AM

This would be great to have!! +1