ASP MVC - C# - .NET 4.5 - Razor
Here is my view model:
public class PackageModel
{
public List<Package> Packages { get; set; }
}
Here is the class:
public class Package
{
public string Name { get; set; }
public string Description { get; set; }
public int Qty { get; set; }
public DateTime Received { get; set; }
}
On the page I have list of controls (textboxes, datepickers, etc). One for each element in the class "Package". Below these controls I have a button that will take the data populated in these controls and add them to a table below. Behind the scenes they are actually getting added to a JSON array. My question is that when I submit this form, how can I bind that JSON array of objects to the model "PackageModel" so it's available in the controller?
Any help is appreciated
UPDATE
Here is the mockup controller
[HttpPost]
public ActionResult SubmitPackage(IList<Package> Packages)
{
}
Here is a console log of the JSON being sent:
[{"Name":"Test","Description":"TestDesc","Qty":"1","Received":"12/12/2013"}]
UPDATE2
Turns out I was just missing the defined content type in my jquery ajax call. Needed this line:
contentType: 'application/json; charset=utf-8'