try to use OData webAPI and call an action with a param, serialized into json without metainformation. So, I want to pass an object of a type:
public class SomeRequest
{
public RequestReason Reason { get; set; }
}
public enum RequestReason
{
New,
Dublicate
}
I've createed a mdel, configured an action:
var action = modelBuilder.Entity<Member>().Action("SomeRequest");
action.Parameter<SomeRequest>("Info");
action.Returns<HttpResponseMessage>();
var model = modelBuilder.GetEdmModel();
configuration.EnableOData(model);
Have code in controller:
[HttpPost]
public HttpResponseMessage RequestIDCard(int key, [FromBody]ODataActionParameters param)
{
object value;
param.TryGetValue("Info", out value);
///!!!!
}
and expect to have value with real type SomeRequest, cast the type and process it... Then I make a POST request with headers
Content-Type: application/json;json=light; charset=utf-8 Accept: application/json;odata=light
and body
{"Info":{"Reason":1}}
But I get object of type "Newtonsoft.Json.Linq.JObject" and sure it cannot be casted! But if I change object type to int, everything work :) Is it a bug of WebAPI OData or I do something wrong?