[英]Angular with MVC tells me error Not found 404
I am using AngularJs with Microsoft ASP.NET MVC when i can get records from Database and Insert new item to Database but when i update item i get Error Not found 404 当我可以从数据库获取记录并将新项插入数据库时,我将AngularJs与Microsoft ASP.NET MVC一起使用,但是当我更新项目时却出现错误404
Here is my code 这是我的代码
C# code: C#代码:
[HttpPut]
public void UpdateContinent(Continent Con)
{
MyDatabaseEntities db = new MyDatabaseEntities();
Continent conti = db.Continents.Find(Con.ContinentId);
conti.ContinentName = conti.ContinentName;
db.SaveChanges();
}
Angular: 角度:
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)
})
}
I have tried this code inside web.config file: 我已经在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>
It didn't work, then i replaced with this code and didn't work too: 它没有用,然后我替换了这段代码,也没有用:
<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>
Please help me. 请帮我。 i am new in Angular..... 我是Angular的新手.....
Thanks in Advance 提前致谢
Your UpdateContinent
method is set as [HttpPut]
but you are sending the request with $http.post
, you should use $http.put
instead: 您的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.