JSONP response from WebAPI to Angular

I have a simple angular controller like below:

angular.module('widget.controllers', [])
  .controller('ProductController', ['$scope','$http', function ($scope, $http) {

      .success(function (data) {


along with a simple action in web api controller:

public HttpResponseMessage GetProducts(string id)                
      var returnData = data;
      string callback = ControllerContext.Request.GetQueryNameValuePairs().Where(kv => kv.Key == "callback").Single().Value;    
      return Request.CreateResponse(HttpStatusCode.OK, returnData, new JsonpMediaTypeFormatter(new JsonMediaTypeFormatter(),callback), new MediaTypeHeaderValue("text/javascript"));

where I am using this formatter. But the response is not containing the callback function's name wrapped around the JSON. It produces sth like:


instead of:


Please suggest for a solution.


Used this to have control over which apis to allow CORS or not. Epic!

Need Your Help

What's the difference between “Any iOS SDK” and “Debug” in Xcode 4 Code Signing?

iphone xcode build xcode4 provisioning

In Xcode 4's Build Settings, there are 2 places to enter a provisioning profile for each build type. The first is "Ad Hoc", "Debug" and "Release". Each of these has another place to put in a provis...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.