Note that there are some explanatory texts on larger screens.

plurals
  1. POJSONP - WebApi EntitySetController
    primarykey
    data
    text
    <p>I have a web api project, and have added a JSONP formatter, and tested it works fine using the standard WebApi implementation. I also need to expose oData - however JSONP formatter seems to be ignored for oData controller using EntitySetController?</p> <pre><code>public class LogsController : EntitySetController&lt;Log, int&gt; { // other code here... [Queryable(PageSize = 50,MaxTop = 100)] public override IQueryable&lt;Log&gt; Get() { return entities.Logs; } protected override Log GetEntityByKey(int key) { return entities.Logs.FirstOrDefault(p =&gt; p.id == key); } } public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet&lt;Log&gt;("Logs"); Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel(); config.Routes.MapODataRoute("ODataRoute", "odata", model); } public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); FormatterConfig.RegisterFormatters(GlobalConfiguration.Configuration.Formatters); } } public class FormatterConfig { public static void RegisterFormatters(MediaTypeFormatterCollection formatters) { var jsonFormatter = formatters.JsonFormatter; jsonFormatter.SerializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; // Insert the JSONP formatter in front of the standard JSON formatter. var jsonpFormatter = new JsonpMediaTypeFormatter(formatters.JsonFormatter); formatters.Insert(0, jsonpFormatter); } } </code></pre> <p>How can I use EntitySetController with JSONP?</p> <p>Sample URL:</p> <pre><code>GET http://example.com/odata/Logs?$orderby=id%20desc&amp;$top=100&amp;callback=jQuery19106219180973712355_1380508978486&amp;_=1380508978487 HTTP/1.1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload