OData V4 modify $filter on server side

Remove [EnableQuery] attribute, your scenario should work, because after using this attribute, OData/WebApi will apply your original query option after you return data in controller, if you already apply in your controller method, then you shouldn’t use that attribute. But if your query option contains $select, those code are not working because the result’s type … Read more

Is there a way in Json.NET serialization to distinguish between “null because not present” and “null because null”?

If you use Json.Net’s LINQ-to-JSON API (JTokens, JObjects, etc.) to parse the JSON, you can tell the difference between a null value and a field that simply doesn’t exist in the JSON. For example: JToken root = JToken.Parse(json); JToken nested = root[“nested”]; if (nested != null) { if (nested.Type == JTokenType.Null) { Console.WriteLine(“nested is set … Read more

URL encoded colon resolves in 400 Bad Request

It seems that ASP.net does not allow colons before the ‘?’ in an URL, even if it is encoded as %3A. For example, these won’t work http://foo.org/api/persons/foo:bar http://foo.org/api/persons/foo%3abar But this works: http://foo.org/api/persons?id=foo%3abar In all examples, we would expect ASP.NET MVC to pass “foo:bar” as an id argument, properly decoded. I just tested this with MVC4 … Read more

Adding a custom query backed Navigation Property to ODataConventionModelBuilder

You have to call “AddNavigationTarget” on the EntitySet. Assume that your namespace is “MyNamespace”, then add the following code to your WebApiConfig.cs. In this way, retrieving the data with “Get: odata/Cars(1)/Parts” will work. var cars = (EdmEntitySet)edmModel.EntityContainers().Single().FindEntitySet(“Cars”); var parts = (EdmEntitySet)edmModel.EntityContainers().Single().FindEntitySet(“Parts”); var carType = (EdmEntityType)edmModel.FindDeclaredType(“MyNamespace.Car”); var partType = (EdmEntityType)edmModel.FindDeclaredType(“MyNamespace.Part”); var partsProperty = new EdmNavigationPropertyInfo(); partsProperty.TargetMultiplicity … Read more

File upload Jquery WebApi

Instead of submit button can you try with normal button – <form enctype=”multipart/form-data”> <label> Using JQuery </label> <input name=”file” type=”file” id=”me” /> <input type=”button” id=”Upload” value=”Upload” /> </form> <script src=”https://stackoverflow.com/questions/21497944/~/Scripts/jquery-1.10.2.min.js”></script> <script type=”text/javascript”> $(function () { $(‘#Upload’).click(function () { var formData = new FormData(); var opmlFile = $(‘#me’)[0]; formData.append(“opmlFile”, opmlFile.files[0]); $.ajax({ url: ‘http://localhost:23133/api/file’, type: ‘POST’, data: … Read more