I have a JSON-like data structure (which I don't want to change) that is currently generated by an .aspx file spitting out javascript. It looks like .NET ate jQuery for lunch, and then vomited...
I'd like to rewrite the entire thing to an MVC controller action that returns a JsonResult, basically by building up an anonymous object and pass it to return Json(data).
However, I can't figure out how to construct the C# object when some of the properties on the JSON object I want to build are actually JavaScript functions. How do I do that?
Example:
I want to create the following JSON-like object:
{
id: 55,
name: 'john smith',
age: 32,
dostuff: aPredefinedFunctionHandle,
isOlderThan: function(other) { return age > other.age }
}
You see that I want to be able to specify both function handles to JavaScript functions that I have defined elsewhere (in .js files, usually) and that I want to define new inline functions.
I know how to build part of that object in C#:
var data = new { id = 55, name = "john smith", age = 32 };
return Json(data);
Is there any good way to do also the rest of it?