Imagine this situation
When using MVC, it is quite simple to send a Javascript code back to the client for execution
public ActionResult DoSomething()
{
return JavaScript("alert('Hello world!');");
}
On the client side, there is a Javascript function that requires a JSON object as input
It looks something like this:
function open(options) {...}
I needed to invoke this function from my action by passing a JSON object produced on the server so I tried doing this
public ActionResult DoSomething()
{
var viewData = new {...};
return JavaScript( "open('" + Json(viewData) + "')" );
}
However, when my Javascript function gets called, instead of receiving data, I get this:
open('System.Web.Mvc.JsonResult')
If anyone could offer some guidance on this issue, it would be greatly appreciated
Many thanks