C# 我试图从ajax调用中调用我编写的Web api Post方法(即postdedication),它给了我一个错误";找不到该资源。”;
我试图通过Postman从ajax调用调用我编写的WebAPI方法 按URL:“ 我的电话C# 我试图从ajax调用中调用我编写的Web api Post方法(即postdedication),它给了我一个错误";找不到该资源。”;,c#,asp.net,ajax,asp.net-web-api,C#,Asp.net,Ajax,Asp.net Web Api,我试图通过Postman从ajax调用调用我编写的WebAPI方法 按URL:“ 我的电话 $.ajax({ type: 'POST', url: 'http://localhost:56881/api/Medication', data: {'MedicationId':44,MedicationName:'dfgsdfgsdfg',DosageFrequency:56,DosageQuantity:464,StartDate:'09/06/2015',EndDate:
$.ajax({
type: 'POST',
url: 'http://localhost:56881/api/Medication',
data: {'MedicationId':44,MedicationName:'dfgsdfgsdfg',DosageFrequency:56,DosageQuantity:464,StartDate:'09/06/2015',EndDate:'09/06/2015',IsActive:1,RefilRemaining:45,TotalQuantity:12,VisitId:4},
contentType: 'application/x-www-form-urlencoded',
dataType: 'json',
success: function(data){ console.log(data) }
});
它给了我找不到的错误资源,请帮助我,就像Dean.DePue已经说过的那样,您正在单独传递参数。ajax调用的方法如下所示:
public HttpResponseMessage Medication(int MedicationId, String MedicationName, int DosageFrequenzy ... etc etc){}
必须传递与viewmodel匹配的对象。我假设这些参数代表您的viewmodel
这将是一种方法:
<script>
var data = "{ MedicationId: 44, MedicationName: xy, DosageFrequenzy: 123 etc.}";
$.ajax({
type: 'POST',
url: 'http://localhost:56881/api/Medication',
data: data,
success: function(data){ console.log(data) }
});
</script>
var data=“{MedicationId:44,MedicationName:xy,DosageFrequenzy:123等];
$.ajax({
键入:“POST”,
网址:'http://localhost:56881/api/Medication',
数据:数据,
成功:函数(数据){console.log(数据)}
});
您的通话情况如何?你通过模型了吗?请把这个添加到你的问题中。它几乎不可读。操作结果期望看到一个json对象,它可以与模型匹配。您正在单独发送字段。我也在邮递员工具中调用它,但它在那里给了我相同的错误
<script>
var data = "{ MedicationId: 44, MedicationName: xy, DosageFrequenzy: 123 etc.}";
$.ajax({
type: 'POST',
url: 'http://localhost:56881/api/Medication',
data: data,
success: function(data){ console.log(data) }
});
</script>