I have a page that posts the following form (this is a simple html form):
point[location1][x]:10
point[location1][y]:20
point[location2][x]:40
point[location2][y]:60
In an action I can obtain the form values using the following model:
public class PlacesModel
{
public Dictionary<string, Dictionary<string, int>> Point { get; set; }
}
Beeing the action:
[HttpPost]
public ActionResult GetPoints(PlacesModel model)
{
// do something with the model here
return View();
}
However, I would rather retrieve the form values with a different model such as:
public class PlacesModel
{
public Dictionary<string, Coord> Point { get; set; }
}
public class Coord
{
public int x { get; set; }
public int y { get; set; }
}
But this doesn't work. The dictionary is filled with 2 entries, one for "location1" and one for "location2" but the coord object is never initialized.
Any thoughts on this?