我正在尝试实例化JsonpMediaTypeFormatter,并且不确定“new”构造中第一个参数需要什么。我在网上找不到任何这方面的例子。非常感谢。
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Net.Http;
using System.Net.Http.Formatting;
using WebApiContrib.Formatting.Jsonp;
namespace IAUWApi
{
public class WebApiApplication : HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// Add these two lines to initialize Routes and Filters:
IAUWApi.App_start.WebAPIConfig.Register(GlobalConfiguration.Configuration);
IAUWApi.App_start.FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
var config = GlobalConfiguration.Configuration;
config.Formatters.Insert(0, new JsonpMediaTypeFormatter("","callback"));
}
}
}
答案 0 :(得分:2)
很可能很久以前用户已经解决了这个问题,但是为了参考,这里应该这样做:
var config = GlobalConfiguration.Configuration;
config.Formatters.Insert(0, new JsonpMediaTypeFormatter(new JsonMediaTypeFormatter()));