最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

MVC后台创建Json(List)前台接受并循环读取实例

来源:动视网 责编:小采 时间:2020-11-27 22:41:02
文档

MVC后台创建Json(List)前台接受并循环读取实例

MVC后台创建Json(List)前台接受并循环读取实例:---------------------------后台------------------- 代码如下:[HttpPost] public JsonResult CheckStock(IEnumerable<pvIdsCount> pvIds) { var resultList = new List<pvIdsCount>
推荐度:
导读MVC后台创建Json(List)前台接受并循环读取实例:---------------------------后台------------------- 代码如下:[HttpPost] public JsonResult CheckStock(IEnumerable<pvIdsCount> pvIds) { var resultList = new List<pvIdsCount>


---------------------------后台-------------------
代码如下:

[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>转换为 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);
});
}
}

文档

MVC后台创建Json(List)前台接受并循环读取实例

MVC后台创建Json(List)前台接受并循环读取实例:---------------------------后台------------------- 代码如下:[HttpPost] public JsonResult CheckStock(IEnumerable<pvIdsCount> pvIds) { var resultList = new List<pvIdsCount>
推荐度:
标签: 后台 json list
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top