Question

This get posted to the server as departments are null

JavaScrtipt code:

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

Web Api Controller

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

Server Model

public class DepartmentViewModel
{
    public int DepartmentId { get; set; }
    public string DepartmentName { get; set; }
}
Was it helpful?

Solution

You have to JSON.stringify the object before you send it in the payload:

 return Restangular.all('records/StartNewDate').post(JSON.stringify(departments));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top