an HTML table requires 2 cells of data from a JSON object that a default.aspx.cs file receives via POST. The task of parsing this JSON object is a little tricky as the data can vary in contents quite considerably. However, VS' immediate window confirms that the JsonResult[""] nomenclature is working fine (IOW, I am succesfully receiving data from a JSON object in a POST request). However, I get inconsistent performance when trying to implement the code below.
if (Request.HttpMethod.ToString() == "POST") {
if (Request.Form["Item"] != null) {
Newtonsoft.Json.Linq.JObject JsonResult = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(Request.Form["Item"]);
if (JsonResult["requestType"] != null) {
cartItem = new CartItem(
"TestCode",
JsonResult["containerType"].ToString(),
JsonResult["resultType"].ToString(),
1,
3.99
);
// populate empty cells with data, place cells in row and place row in table.
foreach (var item in cartItem.getCartCells().Select((value, index) => new { value, index })) {
try {
cartCells.Add(new TableCell());
int i = cartCells.Count() - 1;
cartCells[i].Text = (item.value != null || item.value != "") ? item.value : " - ";
tr.Cells.Add(cartCells[i]);
} catch (Exception ex) {
Response.Write("shopping cart failed to run: " + ex.Message);
break;
}
}
shoppingCart.Rows.Add(tr);
}
}
}
Previously, I had a stub performing a similar task without any problems. Now however, the additional row that this code is supposed to add to my table is not appearing on POST. Strangely, when I add Response.Write("Write a test")
after checking the request method, the table builds just fine. Is there some kind of Async problem going on here? Intellisense and the debugger aren't picking up anything...