Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ASP.NET MVC 4中接受JSON_Asp.net_Asp.net Mvc_Json - Fatal编程技术网

在ASP.NET MVC 4中接受JSON

在ASP.NET MVC 4中接受JSON,asp.net,asp.net-mvc,json,Asp.net,Asp.net Mvc,Json,我将一个JSON发送到ASP.NET的控制器函数,JSON如下所示: [{"Key":"Test23.txt","Size":6,"LastModified":"Thu, 01 Nov 2012 19:35:43 GMT"}, {"Key":"Test25.txt","Size":6,"LastModified":"Wed, 31 Oct 2012 21:02:51 GMT"}, {"Key":"Test28.txt","Size":6,"LastModified":"Thu, 01 Nov 2

我将一个JSON发送到ASP.NET的控制器函数,JSON如下所示:

[{"Key":"Test23.txt","Size":6,"LastModified":"Thu, 01 Nov 2012 19:35:43 GMT"},
{"Key":"Test25.txt","Size":6,"LastModified":"Wed, 31 Oct 2012 21:02:51 GMT"},
{"Key":"Test28.txt","Size":6,"LastModified":"Thu, 01 Nov 2012 19:35:42 GMT"}]
我如何在MVC控制器方法中接受它,以及如何解析它


谢谢。

如果匹配,Mvc将自动将其绑定到viewModel

public ActionResult SaveFiles(List<FileViewModel> filesViewModel){

}
公共类项目
{
公共字符串密钥{get;set;}
公共整数大小{get;set;}
公共日期时间LastModified{get;set;}
}
公共操作结果MyAction(列表项)
{
}

默认型号活页夹可以为您完成所有这些操作。不需要使用任何第三方库。将集合传递到操作时,它们确实需要是可索引的。因此,您必须使用
数组
列表

// First, define your input model.
public class MyModel
{
  public string Key { get; set; }
  public int Size { get; set; }
  public string LastModified { get; set; }
}

// NExt, use that model in your action.
public ActionResult MyAction(MyModel[] things)
{
}

你可以用它来解析。你控制生成这个JSON和发出服务器请求的过程吗?我有一些控制权,我正在开发前端,它使用ExtJs,然后生成JSON。不,我使用空的MVC4项目,没有“默认模型绑定器”。是的,有。。。
public class Item
{
  public string Key {get;set;}
  public int Size {get;set;}
  public DateTime LastModified {get;set;}
}

public ActionResult MyAction(List<Item> items)
{

}
// First, define your input model.
public class MyModel
{
  public string Key { get; set; }
  public int Size { get; set; }
  public string LastModified { get; set; }
}

// NExt, use that model in your action.
public ActionResult MyAction(MyModel[] things)
{
}