[英]Angular with MVC tells me error Not found 404
當我可以從數據庫獲取記錄並將新項插入數據庫時,我將AngularJs與Microsoft ASP.NET MVC一起使用,但是當我更新項目時卻出現錯誤404
這是我的代碼
C#代碼:
[HttpPut]
public void UpdateContinent(Continent Con)
{
MyDatabaseEntities db = new MyDatabaseEntities();
Continent conti = db.Continents.Find(Con.ContinentId);
conti.ContinentName = conti.ContinentName;
db.SaveChanges();
}
角度:
app.controller("myCntrl", function ($scope, $http) {
$scope.Continent = {
ContinentId: '',
ContinentName: ''
};
$scope.Update = function (con) {
$scope.Continent = con;
$http.post('/Home/UpdateContinent', { Con: $scope.Continent })
.success(function (data) {
$('#DivForEdit').modal('hide');
$scope.clear();
$scope.GetAll();
})
.error(function (msg) {
alert(msg)
})
}
我已經在web.config文件中嘗試了以下代碼:
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0"
path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE"
type="System.Web.Handlers.TransferRequestHandler"
resourceType="Unspecified" requireAccess="Script"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
它沒有用,然后我替換了這段代碼,也沒有用:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
請幫我。 我是Angular的新手.....
提前致謝
您的UpdateContinent
方法設置為[HttpPut]
但您使用$http.post
發送請求,而應使用$http.put
:
$scope.Update = function (con) {
$scope.Continent = con;
$http.put('/Home/UpdateContinent', { Con: $scope.Continent })
.success(function (data) {
$('#DivForEdit').modal('hide');
$scope.clear();
$scope.GetAll();
})
.error(function (msg) {
alert(msg)
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.