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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -