Reputation: 1186
I'm trying to post object to odata action, here my code
public class DraftController : ODataController
{
public HttpResponseMessage Attachment([FromODataUri] string key, [FromBody] DraftApi d)
{
try
{
return Request.CreateResponse(HttpStatusCode.Created, "(POST ATTACHMENT) key: " + key + " - id: " + d.id + ", desc: " + d.description);
}
catch (Exception e)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
}
}
}
this is my model
public class DraftApi
{
[Key]
public string id { get; set; }
public string description { get; set; }
}
this is my OData route
config.MapODataServiceRoute(
routeName: "ODataDraft",
routePrefix: "odata/{namespace}",
model: BuildModel<DraftApi>("draft")
);
private static IEdmModel BuildModel<T>(string EntityName) where T : class
{
ODataConventionModelBuilder ODataBuilder = new ODataConventionModelBuilder();
ODataBuilder.EntitySet<T>(EntityName).EntityType.Name = EntityName;
ActionConfiguration attachment = ODataBuilder.EntityType<T>().Action("Attachment");
ODataBuilder.EnableLowerCamelCase();
return ODataBuilder.GetEdmModel();
}
my call is this
Url
http://127.0.0.1/mpssapi/odata/v1/draft('hhh')/Attachment
Headers
Content-Type: application/json
Payload
{id:"a", description: "abc"}
This is my response
{
"error": {
"code": ""
"message": "No HTTP resource was found that matches the request URI 'http://127.0.0.1/mpssapi/odata/v1/draft('hhh')/Attachment'."
"innererror": {
"message": "No routing convention was found to select an action for the OData path with template '~/entityset/key/unresolved'."
"type": ""
"stacktrace": ""
}-
}-
}
I have tried to add namespace to odata route but it doesn't work any ideas? thanks
Upvotes: 0
Views: 2014
Reputation: 2132
The doc may help: http://odata.github.io/WebApi/#04-07-action-parameter-support and call without namespace, you need to turn on UnqualifiedNameCall option like:
config.EnableUnqualifiedNameCall(true);
Upvotes: 1