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)代碼如下,感興趣的朋友可以參考下哈,希望對大家有所幫助
---------------------------后臺-------------------
[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; }
}
---------------------------前臺-------------------
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);
});
}
}
復(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);
});
}
}
您可能感興趣的文章:
- VC創(chuàng)建DLL動(dòng)態(tài)鏈接庫的方法
- VC創(chuàng)建進(jìn)程CreateProcess的方法
- VC實(shí)現(xiàn)動(dòng)態(tài)菜單的創(chuàng)建方法
- VC++創(chuàng)建msi文件的方法
- MVC 5 第一章 創(chuàng)建MVC 5 web應(yīng)用程序
- c#創(chuàng)建vc可調(diào)用的com組件方法分享
- 解析VC中創(chuàng)建DLL,導(dǎo)出全局變量,函數(shù)和類的深入分析
- VC6.0如何創(chuàng)建以及調(diào)用動(dòng)態(tài)鏈接庫實(shí)例詳解
- VC創(chuàng)建圓角dialog的實(shí)現(xiàn)方法
相關(guān)文章
利用docker-compose搭建AspNetCore開發(fā)環(huán)境
這篇文章主要為大家詳細(xì)介紹了利用docker-compose搭建AspNetCore開發(fā)環(huán)境,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07.NET使用YARP根據(jù)域名轉(zhuǎn)發(fā)實(shí)現(xiàn)反向代理
這篇文章介紹了.NET使用YARP根據(jù)域名轉(zhuǎn)發(fā)實(shí)現(xiàn)反向代理的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-09-09asp.net中一個(gè)linq分頁實(shí)現(xiàn)代碼
asp.net中一個(gè)linq分頁實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-12-12輕量級ORM框架Dapper應(yīng)用之實(shí)現(xiàn)DTO
本文詳細(xì)講解了使用Dapper實(shí)現(xiàn)DTO的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03.NET?Core分布式鏈路追蹤框架的基本實(shí)現(xiàn)原理
這篇文章介紹了.NET?Core分布式鏈路追蹤框架的基本實(shí)現(xiàn)原理,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03GridView使用CommandField刪除列實(shí)現(xiàn)刪除時(shí)提示確認(rèn)框
在.net2005提供的GridView中我們可以直接添加一個(gè)CommandField刪除列完后在它的RowDeleting事件中完成刪除2013-09-09