在下面的代码示例中,return语句使用一些对我来说似乎很奇怪的语法。它返回一个新的Json结果,但使用作为参数传入的对象对其进行了初始化?有人可以解释退货声明吗?
[AcceptVerbs("Post")]
public ActionResult EditingInline_Destroy([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
{
if (product != null)
{
productService.Destroy(product);
}
return Json(new[] { product }.ToDataSourceResult(request, ModelState));
}
返回Json数据,我通常会执行以下操作:
// GET: api/authors
[HttpGet]
public JsonResult Get()
{
return Json(_authorRepository.List());
}
答案 0 :(得分:2)
我相信首先要创建一个将其填充到产品中的数组。然后,它使用ToDataSourceResult方法将其转换为Json。
“ ToDataSourceResult”似乎是Teleriks Kendo UI网格使用的一种方法,用于显示JSON中的数据:
https://doylestowncoder.com/2014/04/14/kendoui-understanding-todatasourceresult/