Created
December 20, 2011 19:04
-
-
Save jchadwick/1502782 to your computer and use it in GitHub Desktop.
ASP.NET MVC ActionResult for JSONP responses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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