如何使用Restangular.Js将集合发布到Web Api

时间:2014-01-24 21:48:52

标签: asp.net angularjs asp.net-web-api restangular

此帖子departments null

发布到服务器

JavaScrtipt代码:

var departments = [{ DepartmentName : "Name", DepartmentId : 1}];
Restangular.all('records/StartNewDate').post(departments);

Web Api控制器

public HttpResponseMessage StartNewDate(DepartmentViewModel[] departments)
{
  ....
  ....
}

服务器型号

public class DepartmentViewModel
{
    public int DepartmentId { get; set; }
    public string DepartmentName { get; set; }
}

1 个答案:

答案 0 :(得分:5)

在将对象发送到有效负载之前,您必须对该对象进行JSON.stringify:

 return Restangular.all('records/StartNewDate').post(JSON.stringify(departments));