I have an OData v4
action method which is not working; note however that it was working fine in OData v3
(I am obviously in the process of trying to update my project)
OData Action Method:
[HttpPost]
public Translation Translate(ODataActionParameters parameters)
{
// Implementation
}
Configuration:
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Page>("Pages");
//etc (Other Entity Sets)
var pageEntityType = builder.EntityType<Page>();
var translateAction = pageEntityType.Collection.Action("Translate");
translateAction.Parameter<Guid>("pageId");
translateAction.Parameter<string>("cultureCode");
translateAction.Returns<Translation>();
//etc (Other Actions)
var route = config.MapODataServiceRoute("OData_CMS", "odata/cms", builder.GetEdmModel());
Client AJAX Call:
var data = {
pageId: $("#CultureSelector_PageId").val(),
cultureCode: $("#CultureSelector_CultureCode").val()
};
$.ajax({
url: "/odata/cms/Pages/Translate",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
dataType: "json",
async: false
})
.done(function (json) {
//etc
I tried to see if anything has changed regarding setup for OData actions in version 4, but it seems the same (refer to: Actions and Functions in OData v4 Using ASP.NET Web API 2.2)
EDIT
I found out that OData v4
uses a Default
namespace and implemented that, as follows:
Firstly, just by changing my AJAX call to:
url: "/odata/cms/Pages/Default.Translate",
That didn't work, so I also added:
[ODataRoute("Default.Translate")]
and
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
to my action, as per the instructions at this link: http://damienbod.wordpress.com/2014/06/16/web-api-and-odata-v4-crud-and-actions-part-3/..
Also not working.. I have followed the steps to the letter... either I'm being blind and missing something here or there's a serious problem with the latest version of OData
for Web API
.