欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MVC后臺創(chuàng)建Json(List)前臺接受并循環(huán)讀取實(shí)例

 更新時(shí)間:2013年06月09日 16:11:16   作者:  
MVC后臺創(chuàng)建Json(List)同時(shí)前臺接受并循環(huán)讀取,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下哈,希望對大家有所幫助
---------------------------后臺-------------------
復(fù)制代碼 代碼如下:

[HttpPost]
public JsonResult CheckStock(IEnumerable<pvIdsCount> pvIds)
{
var resultList = new List<pvIdsCount>();
if (pvIds != null)
{
foreach (var pvIdsCount in pvIds)
{
var pvId = pvIdsCount.pvId;
var count = pvIdsCount.count;
var stock = _productService.GetProductVariantById(pvId).StockQuantity;
if (stock - count < 0)
{
var pvIdC=new pvIdsCount();
pvIdC.pvId = pvId;
pvIdC.count = stock;
resultList.Add(pvIdC);
}
}
if (resultList.Count > 0)
{
return Json(new { resultList }); //Json() ---MVC的JSON 方法會(huì)自動(dòng)把List<T> IEnumerable<T>轉(zhuǎn)換為 Json Array<T>
}
else
{
return Json("success");
}
}
return null;
}
public class pvIdsCount
{
public int pvId { set; get; }
public int count { set; get; }
}

---------------------------前臺-------------------
復(fù)制代碼 代碼如下:

AJAX
success: function (data) {
if (data == "success") {
}
} else {
$.each(data.resultList, function (index, value) {
$("#Item_PVId_" + value.pvId).html("This Product's Stock Not Enough.Stock is " + value.count);
});
}
}

相關(guān)文章

最新評論