I'm Using ASP.NET Web API OData with EntitySetController,
Trying to Create Link between two entities: ProductFamily and Product,
OData Action:
public override void CreateLink([FromODataUri] int key, string navigationProperty, [FromBody] Uri link)
ajax request:
$.ajax({
url: "api/ProductFamily(1)/$links/Products",
type: "PUT",
//data missing for the "[FromBody] Uri link"?? what is the format of the data??
success: function (result) {
//do something
}
});
after sending the ajax request, it successfully running into the CreateLink Action, but the link parameter is always null,
what kind of data is missing in the ajax request?? what is the format??
Is there any Sample??
Edit 1: Should be like this??
ajax request:
$.ajax({
url: "api/ProductFamily(1)/$links/Products",
type: "PUT",
data: {"url":"api/Products(5)"}
success: function (result) {
//do something
}
});
this will cause a System.InvalidOperationException: "No MediaTypeFormatter is available to read an object of type 'Uri' from content with media type 'application/json'."
UPDATE:
Problem Solved. Steps:
/odata/Entity(1)/CollectionProp/$refto work but changing the method on the odata controller fromCreateReftoCreateLinkand using/odata/Entity(1)/$links/CollectionPropnow works!! - Paul - Soura Tech LLC