【发布时间】:2019-08-26 02:39:19
【问题描述】:
++ 模型
公共类产品{
公共 int ProductId { 获取;放; }
公共字符串产品名称 { 获取;放; }
公共数据表 dt = 新数据表();
公共类别类别 = 新类别();
}
++控制器
公共 JsonResult 索引(){
产品 dto = new Product();
dto.ProductId = 1;
dto.ProductName = "可口可乐";
返回 Json(dto, JsonRequestBehavior.AllowGet);
}
如何具体Json对象,我的意思是只需要ProductId,ProductName等不需要Json对象。
++想要 { “产品编号”:1, “产品名称”:“可口可乐” }【问题讨论】:
-
一种可能的方法是返回匿名对象,例如
return Json(new { ProductId = dto.ProductId, ... });
标签: c# asp.net json asp.net-mvc