Skip to content

Instantly share code, notes, and snippets.

@jchadwick
Created December 20, 2011 19:04
Show Gist options
  • Save jchadwick/1502782 to your computer and use it in GitHub Desktop.
Save jchadwick/1502782 to your computer and use it in GitHub Desktop.
ASP.NET MVC ActionResult for JSONP responses
public class JsonpResult : ContentResult
{
public object Model { get; set; }
public string Callback { get; set; }
public JsonpResult()
{
ContentType = "application/javascript";
}
public override void ExecuteResult(ControllerContext context)
{
string jsonifiedModel = new JavaScriptSerializer().Serialize(Model);
Content = string.Format("{0}({1});", Callback, jsonifiedModel);
base.ExecuteResult(context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment