dot*_*ner 4 asp.net-mvc asp.net-web-api angularjs
在我的WebAPI asp.net mvc控制器Delete方法中,传入的名为contact的对象即将出现.我已经检查了我的代码,我无法找出根本原因.我的编辑操作以非常类似的方式成功运行.
那么是什么导致webapi asp.net方法中的联系对象参数作为空值进入?
我已经如图所示检查了角度控制器内的接触对象在传递给webapi delete方法之前不是null.

Here is my rest of the code
<div data-ng-controller="ContactDeleteController">
<form name ="deleteContact" data-ng-submit="saveDeleteContact()">
<div>
<label>First Name: </label>
<input required type="text" placeholder="Enter First Name" data-ng-model="contact.FirstName"/>
</div>
<div>
<label>Last Name: </label>
<input required type="text" placeholder="Enter Last Name" data-ng-model="contact.LastName"/>
</div>
<div>
<label>Email Address: </label>
<input required type="text" placeholder="Enter Email Address" data-ng-model="contact.EmailAddress"/>
</div>
<div>
<label>Cell Phone Number: </label>
<input required type="text" placeholder="Enter Phone Number" data-ng-model="contact.PhoneNumber"/>
</div>
<div></div>
<div>
<button class="btn btn-primary" type="submit">Delete</button>
</div>
</form>
</div>
var ContactDeleteController = function ($scope, $http, $location) {
var contactId = $location.absUrl().match(/\/Delete\/(.*)/)[1];
$http.get("/api/ContactWeb/" + contactId)
.then(function (response) {
$scope.contact = response.data;
});
$scope.saveDeleteContact = function () {
var con = $scope.contact;
$http.delete("/api/ContactWeb", con)
.then(function (response) {
$scope.contact = response.data;
});
window.location = "/Contact/Index";
};
};
Run Code Online (Sandbox Code Playgroud)

HTTP不允许DELETE与body.尝试发送在URI参数(查询字符串等),并在网络API,将数据绑定到复杂类型Contact使用[FromUri].
| 归档时间: |
|
| 查看次数: |
5879 次 |
| 最近记录: |