I’ve created a matrix-type form with dynamic rows and columns. The cells contain input fields that need to be handled by C# (MVC4, ASP.NET 4). The form looks like this (simplified):
<form action="~/Administration/PriceMatrix" method="post">
<input type="text" name="Prices[1][0][1]" value="15.00" />
<input type="text" name="Prices[1][0][2]" value="12.50" />
<input type="text" name="Prices[1][1][1]" value="10.00" />
<input type="text" name="Prices[1][1][2]" value="7.50" />
</form>
The matching controller is still empty:
[HttpPost]
public ActionResult PriceMatrix(object form)
{
}
When I use Request.Form I can of course access all the values, but they’re not (de)serialized into an array. So I cannot do this: Request.Form["Prices"][0] or something like that. Instead, I can only access them using their full names: Request.Form["Prices[1][0][1]"] (=15.00). Of course I can loop thru the array and split the Key for each value, but I would like to do it some other way. I’ve tried to replace object form with another type or custom object containing lists etc., but so far no luck.
Any suggestions?
You need to get the values as custom type. I suggest you to serialize your form to JSON, and then on server side access the serialized form in any way you like.