我希望我的“全部编辑”按钮进行ajax调用,将300个项目发送到我的jsonresult控制器方法进行更新,但它根本没有点击我的端点,网络选项卡显示状态代码为302.似乎打了我的控制器方法,并且当我尝试发送一个或10个项目时工作正常,所以我猜测它与300相关太多而无法传入?我附加了部分html + javascript函数+ ajax调用+控制器方法。
我已经查看了其他答案,但它们似乎与登录身份验证或预期有302的情况有关。还有帖子建议一次发送较小的数组,但我想确定问题首先是相关的。
$scope.saveAllDays = function () {
var newValue = angular.element("#editAll").val();
var savedCustomers = [];
angular.forEach(angular.element(".customer"), function (customer, index) {
var currentCustomerId = angular.element(customer).attr("id");
for (var i = 0; i < $scope.customers.length; i++) {
if ($scope.customers[i].Id == currentCustomerId) {
var savedCustomer = $scope.customers[i];
savedCustomer.ArchiveDays = newValue;
savedCustomers.push(savedCustomer);
break;
}
}
})
console.log(savedCustomers);
$.ajax({
type: "PUT",
url: "/JobArchive/UpdateArchivePeriods",
data: JSON.stringify(savedCustomers),
contentType: "application/json",
dataType: "json",
success: onUpdateAllSuccess,
error: onUpdateAllError
})
}
&#13;
<div id="archiveConfigTab" class="tab-pane fade">
<div class="bumper"></div>
<div class="container cust-body">
<div class="search">
<label>Search:</label>
<input type="text" id="nameInput" size="100" ng-model="customerName" />
</div>
<div id="customer-title">
Customers
</div>
<div id="editAllDays">
<p class="edit-all-btn pull-right">
<button class="btn btn-sm btn-default" ng-click="showEditAll($event)">Edit All <i class="fa fa-edit"></i></button>
</p>
<div class="edit-mode hidden">
<input type="number" id="editAll" placeholder="# of days" min="0" />
<button class="btn btn-sm btn-primary" ng-click="saveAllDays()">Save</button>
</div>
</div>
<div id="{{customer.Id}}" class="customer" ng-repeat="customer in customers | orderBy : 'Name' | filter : customerName">
<p class="cust-row">{{customer.Name}}</p>
<p class="cust-row pull-right">
<button class="btn btn-sm btn-default" ng-click="toggleInput($event)">edit <i class="fa fa-edit"></i></button>
</p>
<p>Archive Period: {{customer.ArchiveDays}} days</p>
<div class="edit-mode-row hidden">
<input type="number" ng-keypress="checkEnter($event, saveDays)" class="archivePeriod" placeholder="# of days" min="0" />
<button class="btn btn-primary btn-sm" ng-click="saveDays($event)">save</button>
</div>
</div>
</div>
<div class="bumper"></div>
</div>
&#13;
[HttpPut]
public JsonResult UpdateArchivePeriods(List<LAG.Models.Customer> updatedCustomers)
{
List<ConfiguredCustomerViewModel> results = new List<ConfiguredCustomerViewModel>(); // Initialize List of stuff to return to front
foreach (var customer in updatedCustomers) // Loop through and update each
{
bool updateSuccess = LAG.API.DAL.CustomerRepository.GetRepository().SaveArchiveDays(customer.ArchiveDays, customer.Id);
if (updateSuccess)
{
ConfiguredCustomerViewModel result = new ConfiguredCustomerViewModel();
result.Id = customer.Id;
result.ArchiveDays = customer.ArchiveDays;
results.Add(result);
}
}
return Json(results);
}
答案 0 :(得分:0)
修剪我的对象,只包括我需要为我工作的2个属性。
我仍然感到困惑的是,为什么我第一次收到302试图将我重定向到错误页面,因为我传入的数据量并不是触及413状态所需的5TB附近码。这真让我烦恼。