my Json code is
ListOrderDetails.push({ // Add Order Details to array
"OrderType": OrderType,
"CaseNumber": CaseNumber,
"OrderNumber": OrderNumber,
"OrderStatus": OrderStatus,
"Reason": Reason,
"Coments": Coments
});
var Params = { "Geo": Geography, "GeoId": GeographyID, "CountryCode": CountryCode, "Segment": Segment, "SubsegmentID": SubSegmentID, "OrderDetails": ListOrderDetails };
//var Params = { "Geo": Geography, "GeoId": GeographyID, "CountryCode": CountryCode, "Segment": Segment, "SubsegmentID": SubSegmentID };
$.ajax({
type: "POST",
url: "MyDataVer1.aspx/SaveManualEntry",
contentType: "application/json",
data: JSON.stringify(Params),
dataType: "json",
success: function(response) {
alert(response);
},
error: function(xhr, textStatus, errorThrown) {
alert("xhr : " + xhr);
alert("textStatus : " + textStatus);
alert("errorThrown " + errorThrown);
}
});
c# webmethod is
[WebMethod]
public static int SaveManualEntry(string Geo, int GeoId, string CountryCode,
string Segment, string SubsegmentID,
object[] OrderDetails)
{
try
{
int TotalOrderCount = 0;
int Successcount = 0;
return Successcount;
}
catch (Exception ex)
{
throw ex;
}
}
How to get values from the Object orderDetails. I cant use indexing.
Object.values() returns an array whose elements are the enumerable property values found on the object. The ordering of the properties is the same as that given by looping over the property values of the object manually.
To get the values of an object as an array, use the Object. values() method, passing it the object as a parameter. The method returns an array containing the object's property values in the same order as provided by a for ... in loop. Copied!
You can use reflection:
foreach(var order in orderDetails)
{
string orderType = (string)order.GetType().GetProperty("OrderType").GetValue(order);
// other properties
}
You first need to create an order detail object:
public class OrderDetail
{
public string OrderType { get; set; }
public string CaseNumber { get; set; }
public string OrderNumber { get; set; }
public string OrderStatus { get; set; }
public string Reason { get; set; }
public string Coments { get; set; }
}
Then change your web method to this:
[WebMethod]
public static int SaveManualEntry(string Geo, int GeoId, string CountryCode,
string Segment, string SubsegmentID,
List<OrderDetail> OrderDetails)
{
try
{
int TotalOrderCount = 0;
int Successcount = 0;
return Successcount;
}
catch (Exception ex)
{
throw ex;
}
}
Which accepts a List<OrderDetails>
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With