I have a control that emits a JSON array that I need to convert into a list on my Model on the controller, and trying to find a generic, scalable way of doing this. I'm assuming there is something simple and obvious.
So I get an array like this:
{
{ AddressId: 1, HouseNumber: 1, Street: "Any Street" },
{ AddressId: 2, HouseNumber: 2, Street: "Any Street" },
{ AddressId: 3, HouseNumber: 5, Street: "Any Street" },
{ AddressId: 4, HouseNumber: 10, Street: "Any Street" },
{ AddressId: 5, HouseNumber: 1536, Street: "Any Street" }
}
The Model:
public class AddressListModel {
public string AnotherFormInput { get; set; }
...
// A selection of other form input values that are on the page.
...
public IList<AddressViewModel> Addresses { get; set; }
}
public class AddressViewModel {
public int AddressId { get; set; }
public int HouseNumber { get; set; }
public int Street { get; set; }
}
So the question is, if I already have a lot of form parameters in this form, and I want to then take this JSON array that I gather via Javascript prior to the Form post, how can I think append that array as a standard form parameter.
This isn't being done via Ajax, just a standard Form post.