[英]Can't post list of objects, also only limited number of response headers are allowed
抱歉,我對Angular(以及整個ASP.net環境)有點陌生。 我已經創建了從API .net服務檢索的客戶列表。 然后,我在每個復選框旁邊放置復選框,以指示它們是活躍客戶還是非活躍客戶。 想法是,當您滾動列表時,可以選中這些框,然后按“保存”,這將更新客戶活躍或不活躍的數據庫。 這是我的嘗試:
app.controller("CustomersController", function ($scope, $http) {
$http.get(serviceURL + "/customers")
.then(function onSuccess(response) {
$scope.customers = response.data;
}, function onError(response) {
//~
});
$scope.saveCustomers = function () {
$http.post(serviceURL + "/customers", $scope.customers)
.then(function onSuccess(response) {
//~
}, function onError(response) {
//~
});
};
});
在這里,通過在HTML文件中按下保存按鈕來調用saveCustomers,並在范圍內更改了選中標記的值。 發布此消息時,我收到400 HTTP響應(即使它返回的對象列表在控制台中看起來也不錯)。 我什至試圖將JSONconvert排除在外。 然后,我進行了迭代,並嘗試為$ scope.customers中的每個對象在循環中進行發布。 但是,這返回了409 HTTP響應,我不確定這對我的帖子意味着什么。 我已經嘗試過PUT,但標頭中不允許這樣做。 我試圖通過將其添加到Web.config文件來解決此問題:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
</modules>
....
以及在IIS管理器中更改處理程序映射,以便ExtensionlessUrlHandler-Integrated-4.0包含動詞PUT和DELETE。 我有一個“添加客戶”頁面,該頁面對表單上的單個對象使用了一個帖子,並且效果很好。 我已經花了幾個小時嘗試所有可能的方法,但是我無法讓這個簡單的方法起作用。 另外,這是我的HTML供參考:
<tr ng-repeat="a in customers | filter:txtFilter">
<td>
{{a.customer_id}}
</td>
<td>
{{a.customer_name}}
</td>
<td>
{{a.customer_phone}}
</td>
<td>
<input type="checkbox"
name="selectedInactives[]"
value="{{a.inactive}}"
ng-checked="a.inactive"
ng-click="toggleSelection(a.inactive)"
ng-true-value="{{1}}"
ng-false-value="{{0}}"
/> {{a.inactive}}
</td>
</tr>
(注意:不用擔心ng-true-value或false值設置為整數值,這沒有什么區別)
試試吧:
$http.post(serviceURL + "/customers",{customrers: $scope.customers}).then();
將prop名稱放在您的后端函數中,而不是“客戶:”。
不要在ng-*-value
指令中使用插值( {{ }}
)。 帶雙花括號的插值會將AngularJS表達式轉換為字符串。
要使用數值:
<input type="checkbox"
name="selectedInactives[]"
̶v̶a̶l̶u̶e̶=̶"̶{̶{̶a̶.̶i̶n̶a̶c̶t̶i̶v̶e̶}̶}̶"̶
̶n̶g̶-̶c̶h̶e̶c̶k̶e̶d̶=̶"̶a̶.̶i̶n̶a̶c̶t̶i̶v̶e̶"̶
ng-model="a.inactive"
̶n̶g̶-̶c̶l̶i̶c̶k̶=̶"̶t̶o̶g̶g̶l̶e̶S̶e̶l̶e̶c̶t̶i̶o̶n̶(̶a̶.̶i̶n̶a̶c̶t̶i̶v̶e̶)̶"̶ ̶
ng-change="toggleSelection(a)"
̶n̶g̶-̶t̶r̶u̶e̶-̶v̶a̶l̶u̶e̶=̶"̶{̶{̶1̶}̶}̶"̶ ̶
ng-true-value="1"
̶n̶g̶-̶f̶a̶l̶s̶e̶-̶v̶a̶l̶u̶e̶=̶"̶{̶{̶0̶}̶}̶"̶
ng-false-value="0"
/> {{a.inactive}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.