asp.net mvc - How to get .net web api in jsonP, although it returns json data by default -
i working on .net web api in asp.net mvc5 project...
by default returns xml or json...in project json/xml data returning fine...
i looking setting can response in jsonp....
web api config :
public static void register(httpconfiguration config) { // web api configuration , services // web api routes config.maphttpattributeroutes(); config.routes.maphttproute( name: "smallbizapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); config.formatters.clear(); // config.formatters.add(new xmlmediatypeformatter()); // config.formatters.insert(0, new jsonpmediatypeformatter(new jsonmediatypeformatter())); config.formatters.add(new jsonmediatypeformatter()); // config.formatters.add(new xmlmediatypeformatter()); }
i new webapi's , looking way please help.... time....
try replacing
config.formatters.add(new jsonmediatypeformatter());
with
config.formatters.jsonformatter.supportedmediatypes.add(new mediatypeheadervalue("text/html"));
i did on recent project. , worked fine.
Comments
Post a Comment