手机
当前位置:查字典教程网 >编程开发 >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)前台接受并循环读取实例】相关文章:

litjson读取数据示例

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

iis的http 500内部服务器错误的解决

ConfiguraionSource节点及多个配置文件的应用

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

让你的.NET程序兼容不同版本的Dll文件

ASP.NET中动态控制RDLC报表

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

ASP.NET 高性能分页代码

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

精品推荐
分类导航