Jquery 如何使用ajax将Json对象发送到ODataController
我有一个OData服务,我想向它发送一个Json对象。但我不明白 这是我的代码: 在MVC控制器中Jquery 如何使用ajax将Json对象发送到ODataController,jquery,ajax,asp.net-mvc,json,odata,Jquery,Ajax,Asp.net Mvc,Json,Odata,我有一个OData服务,我想向它发送一个Json对象。但我不明白 这是我的代码: 在MVC控制器中 public class SyncController : ODataController { [HttpPost] public IQueryable<AppWriteError> GetSync(AppSyncDataModel data) { // do some stuff } } 这是我的ajax调用: $.ajax({ url: url,
public class SyncController : ODataController
{
[HttpPost]
public IQueryable<AppWriteError> GetSync(AppSyncDataModel data)
{
// do some stuff
}
}
这是我的ajax调用:
$.ajax({
url: url,
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(synchData) ,
success: function () {
alert("success :-)");
},
error: function () {
alert("fail :-(");
}
因此,如果我运行此命令,AppSynchDataModel始终为空,我会收到以下消息:
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"No HTTP resource was found that matches the request URI 'http://localhost:3367/odata/Sync'."
},"innererror":{
"message":"No routing convention was found to select an action for the OData path with template '~/entityset'.","type":"","stacktrace":""
}
}
}
我该怎么做?也许可以尝试将您的url更改为-看起来像是映射问题。您可能还想添加一个简单的get映射,只需确保您可以从浏览器/curl等中点击即可。这是我的Json{UserId:3d4bd913-ab5e-4d52-984d-6cb4b7eba155}不,我的辩护是,在这个地址上是我的OData服务正在运行,当我调试时,您看到的是/OData/而不是/data/?对不起,不是OData。我现在改了。。。谢谢
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"No HTTP resource was found that matches the request URI 'http://localhost:3367/odata/Sync'."
},"innererror":{
"message":"No routing convention was found to select an action for the OData path with template '~/entityset'.","type":"","stacktrace":""
}
}
}