时间:2016-02-15 21:44 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【MVC后台创建Json(List)前台接受并循环读取实例】,下面是详细的讲解!
MVC后台创建Json(List)前台接受并循环读取实例
[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; }
}
关于MVC后台创建Json(List)前台接受并循环读取实例的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【服务器】asp.net页面状态管理cookie和服务器状
- 如何取消.net后台线程的执行
- 【WeakReference】WeakReference(弱引用)让GC需要
- 【ajax格式】asp.net中在用ajax格式传递数据到asp
- 【字符文本】asp.net 数据绑定 使用eval 时候报
- 【Repeater控件】.NET实现Repeater控件+AspNetPag
- 【客户端】获取客户端IP地址c#/vb.net各自实现代
- 【asp】asp.net上传execl文件后 在页面上加载显示
- 【JSON】浅析JSON序列化与反序列化-序列化-反序列
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
