最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2013年06月09日 16:11:16   作者:  
MVC后臺創(chuàng)建Json(List)同時前臺接受并循環(huán)讀取,具體實現(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 方法會自動把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)文章

最新評論

萨嘎县| 习水县| 衡阳县| 衡水市| 沐川县| 彭山县| 大姚县| 黑水县| 泾源县| 高州市| 宜阳县| 潜山县| 禄劝| 台东市| 六枝特区| 武功县| 麻城市| 庐江县| 太保市| 嘉祥县| 大丰市| 昌都县| 定陶县| 屏边| 湛江市| 天祝| 庆云县| 达日县| 于都县| 正安县| 克拉玛依市| 上思县| 玛多县| 正镶白旗| 韶山市| 永寿县| 杭锦后旗| 子长县| 香港| 岳池县| 广安市|