手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >MVC后台创建Json(List)前台接受并循环读取实例
MVC后台创建Json(List)前台接受并循环读取实例
摘要:---------------------------后台-------------------复制代码代码如下:[HttpPost]pub...

---------------------------后台-------------------

复制代码 代码如下:

[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)前台接受并循环读取实例】相关文章:

ASP.Net Post方式获取数据流的一种简单写法

asp.net C#检查URL是否有效的方法

litjson读取数据示例

DotNet2.0 生成网站的测试

实现ASP.NET多文件上传程序代码

asp.net通过配置文件连接Access的方法

XmlReader 读取器读取内存流 MemoryStream 的注意事项

ASP.NET MVC中将控制器分离到类库的实现

在ASP.NET MVC 4 on Mono中使用OracleClient in CentOS 6.x的问题记录

ASP.NET技巧:做个DataList可分页的数据源

精品推荐
分类导航