I'm having trouble figuring out a way to access the following json returned from my controller:
[{"ID":1,"seatnum":"A1","status":0},{"ID":2,"seatnum":"A2","status":0}]
I am trying to to access the each seatnum value (A1, A2) to perform the following function:
$.ajax({
url: 'seats/getseats',
dataType: "JSON",
error: function (data) {
$("table tr img").removeClass("available").attr("src", "images/taken.gif");
alert("error")
}
}).done(function (data) {
for (var i = 0; i < data.length; i++) {
//alert(data[i].seatnum);
var seatLetter = data[i][0];
var seatNumber = data[i].substr(1);
var $target = getImgFromSeat(seatLetter, seatNumber);
$target.removeClass("available").attr("src", "images/taken.gif");
}
If it helps my Controller method is:
//
// GET: /seats/
public ActionResult Index()
{
return View(db.seats.ToString());
}
public JsonResult getseats()
{
var taken = from b in db.seats
select b;
taken = taken.Where(b => b.status.Equals(0));
return Json(taken, JsonRequestBehavior.AllowGet);
}