gpt4 book ai didi

c# - "The requested resource does not support HTTP method ' PUT' ASP.Net Web API

转载 作者:行者123 更新时间:2023-11-30 12:22:24 28 4
gpt4 key购买 nike

我的 jQuery Put 请求不起作用,当我在 Debug模式下运行我的代码时,put 函数没有被调用,从 FireBug 中我可以看到这个错误:

The requested resource does not support HTTP method 'PUT'

这是我的 jQuery 代码和 API Controller :

<script>
$(document).ready(function() {
$('#success').hide();

function onSelect(e) {
$("#Type").prop("checked", false);

var name = $("#TreeView").data("kendoTreeView").dataItem(e.node).Name;
var accountId =$("#TreeView").data("kendoTreeView").dataItem(e.node).AccountId;

$("#AccountID").val(accountId).prop("disabled",true);

$("#Name").val(name).prop("disabled",true);

var type = $("#TreeView").data("kendoTreeView").dataItem(e.node).Nature;

$("#NatureAccountId").data("kendoDropDownList").value(type);

$("#AccountTypeId").data("kendoDropDownList").value(type);
$("#AccountTypeId").data("kendoDropDownList").enable(false);

$("#BaseCurrencyId").data("kendoDropDownList").value(type);

$("#ContraryToNatureCtrlId").data("kendoDropDownList").value(type);

$("#BudgetCtrlTypeId").data("kendoDropDownList").value(type);

var descrip = $("#TreeView").data("kendoTreeView").dataItem(e.node).Description;
$("#Description").val(descrip);

var idd = $("#TreeView").data("kendoTreeView").dataItem(e.node).ParentID;
$("#ParentID").val(idd);

var pName = $("#TreeView").data("kendoTreeView").dataItem(e.node).ParentName;
$("#ParentName").val(pName).prop("disabled", true);

var isActive = $("#TreeView").data("kendoTreeView").dataItem(e.node).IsActive;
$("#IsActive").val(isActive);

$("input:radio[name=Type][value='" + type + "']").prop("checked", true);
$("input[name=Type]").prop("disabled", true);
}

var accountchild = {
type: "odata",
transport: {
read: {
url: function(options) {
return kendo.format("/api/Account/GetAccountChilds?ParentID={0}&OrganizationID={1}", options.AccountId, @Session["OrganizationID"].ToString());
}

}
},
schema: {
model: {
id: "AccountId",
hasChildren: "HasChildren",
type: "Type",
name: "Name"

}
}
};

$("#TreeView").kendoTreeView({
dataSource: new kendo.data.HierarchicalDataSource({
type: "odata",
transport: {
read: {
url: "/api/Account/GetAllAccountParrentInfos?OrganizationID=@Session["OrganizationID"].ToString()",
dataType: "json"
}
},
schema: {
data: function(data) {
return data;
},
total: function(data) {
return data['odata.count'];
},
model: {
id: "AccountId",
hasChildren: "HasChildren",
children: accountchild,
type: "Nature",
name: "Name",
Description:"Description",
isActive:"IsActive",
parentName:"ParentName",
ParentID:"ParentID"
}
}
}),
select: onSelect,
dataTextField: ["DisplayName", "DisplayName"],
dataValueField: "AccountId"
});
});
</script>

<script>
$("#AccountTypeId").kendoDropDownList({
dataTextField: "Type",
dataValueField: "Id",
optionLabel: "انتخاب نوع حساب",
dataSource: {
transport: {
read: {
dataType: "json",
url: "/api/Account/GetAllAccounttypes"
}
}
}
});

$("#BaseCurrencyId").kendoDropDownList({
dataTextField: "Currency",
dataValueField: "Id",
optionLabel: "انتخاب ارز پایه",
dataSource: {
transport: {
read: {
dataType: "json",
url: "/api/Account/GetBaseCurrencies"
}
}
}
});

$("#NatureAccountId").kendoDropDownList({
dataTextField: "Nature",
dataValueField: "Id",
optionLabel: "انتخاب ماهیت حساب",
dataSource: {
transport: {
read: {
dataType: "json",
url: "/api/Account/GetNatureAccounts"
}
}
}
});

$("#ContraryToNatureCtrlId").kendoDropDownList({
dataTextField: "Ctrl",
dataValueField: "Id",
optionLabel: "کنترل خلاف ماهیت",
dataSource: {
transport: {
read: {
dataType: "json",
url: "/api/Account/GetContraryToNatureCtrls"
}
}
}
});

$("#BudgetCtrlTypeId").kendoDropDownList({
dataTextField: "CtrlType",
dataValueField: "Id",
optionLabel: "نوع کنترل بودجه",
dataSource: {
transport: {
read: {
dataType: "json",
url: "/api/Account/GetBudgetCtrlTypes"
}
}
}
});
</script>

<script>
$("#btn_edit").click(function() {
var account = {
"ParentID": $("#ParentID").val(),
"AccountID": $("#AccountID").val(),
"Name": $("#Name").val(),
"Description": $("#Description").val(),
"OrganizationID": $("#OrganizationID").val(),
"IsDeleted": false,
"RemainObligor": null,
"Editable": true,
"HasChildren": false,
//"Type": $("input[name=Type]").prop("checked", true).val(),
"IsActive": $("#IsActive").prop("checked"),
"BaseCurrencyId": $("#BaseCurrencyId").val(),
"AccountTypeId": $("#AccountTypeId").val(),
"BudgetCtrlTypeId": $("#BudgetCtrlTypeId").val(),
"ContraryToNatureCtrlId": $("#ContraryToNatureCtrlId").val(),
"NatureAccountId": $("#NatureAccountId").val()

};

$.ajax({
type: "PUT",
url: '/api/Account/Editt',
data: JSON.stringify(account),
contentType: "application/json;charset=utf-8",
processData: true,
success: function(data) {
alert(`'موفق'`);
},
error: function() {
alert('ناموفق');

}
});
});
</script>


[AcceptVerbs("POST", "Get")]
[System.Web.Http.HttpPost]
public void Edittt([FromBody]AccountGridViewModel a)
{
Account account=new Account();
account.AccountID = a.AccountID;
account.AccountTypeId = a.AccountTypeId;
account.Name = a.Name;
account.ParentID = a.ParentID;
account.NatureAccountId = a.NatureAccountId;
account.ContraryToNatureCtrlId = a.ContraryToNatureCtrlId;
account.BaseCurrencyId = a.BaseCurrencyId;
account.BudgetCtrlTypeId = a.BaseCurrencyId;
account.Description = a.Description;
account.IsActive = a.IsActive;
account.Organization = a.Organization;
account.OrganizationID = a.OrganizationID;
_accountService.UpdateAccount(account);
}

最佳答案

删除

[AcceptVerbs("POST", "Get")]

并改变

[System.Web.Http.HttpPost]

[System.Web.Http.HttpPut]

HttpPost 是 AcceptVerbs("POST") 的简写。没有你在哪里告诉 Controller 接受 PUT。我不认为你可以让一个 Controller 方法接受多个动词,即使你可以我觉得更清晰的实现是有两个同名的方法,一个用 HttpGet 修饰,一个用 HttpPut 修饰。

关于c# - "The requested resource does not support HTTP method ' PUT' ASP.Net Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41048299/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com