hastiam
شنبه 13 آبان 1396, 10:18 صبح
سلام
من میخوام لیستی از دیتا رو از سمت کلاینت بگیرم و به سمت سرور بفرستم تا عملیات ویرایش انجام شود برای اینکار از روش زیر استفاده کردم :
function updateOrder() {
var count = 10;
var url = '@Url.Action("Update", new { Controller = "CustomerOrders" })';
var customerOrders = new Array();
var data={};
for (var j = 0; j < count; j++) {
data.GoodsValue = $("#Results_" + j + "__GoodsValue").val();
data.Quantity = $("#Results_" + j + "__Quantity").val();
data.ID = $("#Results_" + j + "__ID").val();
data.Comments = $("#Results_" + j + "__Comments").val();
data.PaymentStatus = $("#Results_" + j + "__PaymentStatus").val();
data.Price = $("#Results_" + j + "__Price").val();
customerOrders.push(data);
data={};
}
customerOrders = JSON.stringify({ 'Params': customerOrders });
$.ajax({
contentType:'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: url,
data: customerOrders,
success: function (info) {
.....
},
error: function (e, x) {
.....
}
});
}
public JsonResult Update(List<CustomerOrders> Params)
{
try
{
foreach (var order in Params)
{
var orderInfo = repository.CustomerOrders.Where(i => i.ID == order.ID).FirstOrDefault();
orderInfo.UpdatedBy = User.Identity.Name;
orderInfo.Updated = DateTime.Now;
orderInfo.Quantity = order.Quantity;
orderInfo.GoodsValue = order.GoodsValue;
orderInfo.Comments = order.Comments;
orderInfo.Price = order.Price;
orderInfo.Date = DateTime.Now;
orderInfo.PaymentStatus = order.PaymentStatus;
orderInfo.IsApproved = true;
repository.Update(orderInfo);
}
result.Message = "ثبت سفارش با موفقیت انجام شد.";
result.Successfull = true;
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
result.Successfull = false;
result.Message = ex.Message;
}
return Json(result);
}
مشکلی که وجود داره اینه که اگه آرایه customerOrders خیلی خیلی طولانی باشه کل آرایه از سمت کلاینت گرفته نمیشه چطوری میشه این مشکل رو حل کرد؟
من میخوام لیستی از دیتا رو از سمت کلاینت بگیرم و به سمت سرور بفرستم تا عملیات ویرایش انجام شود برای اینکار از روش زیر استفاده کردم :
function updateOrder() {
var count = 10;
var url = '@Url.Action("Update", new { Controller = "CustomerOrders" })';
var customerOrders = new Array();
var data={};
for (var j = 0; j < count; j++) {
data.GoodsValue = $("#Results_" + j + "__GoodsValue").val();
data.Quantity = $("#Results_" + j + "__Quantity").val();
data.ID = $("#Results_" + j + "__ID").val();
data.Comments = $("#Results_" + j + "__Comments").val();
data.PaymentStatus = $("#Results_" + j + "__PaymentStatus").val();
data.Price = $("#Results_" + j + "__Price").val();
customerOrders.push(data);
data={};
}
customerOrders = JSON.stringify({ 'Params': customerOrders });
$.ajax({
contentType:'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: url,
data: customerOrders,
success: function (info) {
.....
},
error: function (e, x) {
.....
}
});
}
public JsonResult Update(List<CustomerOrders> Params)
{
try
{
foreach (var order in Params)
{
var orderInfo = repository.CustomerOrders.Where(i => i.ID == order.ID).FirstOrDefault();
orderInfo.UpdatedBy = User.Identity.Name;
orderInfo.Updated = DateTime.Now;
orderInfo.Quantity = order.Quantity;
orderInfo.GoodsValue = order.GoodsValue;
orderInfo.Comments = order.Comments;
orderInfo.Price = order.Price;
orderInfo.Date = DateTime.Now;
orderInfo.PaymentStatus = order.PaymentStatus;
orderInfo.IsApproved = true;
repository.Update(orderInfo);
}
result.Message = "ثبت سفارش با موفقیت انجام شد.";
result.Successfull = true;
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
result.Successfull = false;
result.Message = ex.Message;
}
return Json(result);
}
مشکلی که وجود داره اینه که اگه آرایه customerOrders خیلی خیلی طولانی باشه کل آرایه از سمت کلاینت گرفته نمیشه چطوری میشه این مشکل رو حل کرد؟