我在.Net 4.5中有一个oData应用程序.oData端点工作正常,但我想在控制器上创建自定义操作,以便在给定电子邮件地址时在Customer记录上设置标志.
这是我的客户端代码(使用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) {
// ...
});
Run Code Online (Sandbox Code Playgroud)
这是我的服务器代码:
public class CustomersController : EntitySetController<Customer, int>
{
private DBEntities db = new DBEntities();
// ... other generated methods here
// my custom method
[HttpPut]
public Boolean SetAlertFlag([FromBody] string email)
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
永远不会调用服务器方法.当我在浏览器中输入此URL时,http://localhost:60903/odata/Customers/SetAlertFlag我收到此错误:"检测到无效操作."SetAlertFlag'不是可以绑定到'Collection([Skirts.Models.Customer Nullable = False])'的操作."
EntitySetController类可以没有自定义方法吗?我该怎么做呢?