I have an oData application in .Net 4.5. The oData endpoints work fine, but I want to create a custom action on the controller to set a flag in the client entry when it is given an email address.
Here is my client code (using AngularJS):
$http({
method: 'POST',
url: '/odata/Customers/SetAlertFlag',
data: { 'email': 'test@test.com'}
}).success(function (data, status, headers, config) {
}).error(function (data, status, headers, config) {
});
Here is my server code:
public class CustomersController : EntitySetController<Customer, int>
{
private DBEntities db = new DBEntities();
[HttpPut]
public Boolean SetAlertFlag([FromBody] string email)
{
return true;
}
}
The server method is never called. When I type this URL in the browser http://localhost:60903/odata/Customers/SetAlertFlag
, I get this error: "An invalid action was detected." SetAlertFlag "is not an action that can be associated with" Collection ([Skirts. Model. Custom Nullable = False]) "."
EntitySetController classes don't have custom methods? How else should I do this?