In ASP.NET MVC, I\'ve an action which takes user input about rows and columns and then it navigates to the action which generates required number of rows and columns based on th
Simplest way would be to post the number of rows and columns back with the input values:
@using (Html.BeginForm())
{
@for (int k = 0; k < Model.Rows.Capacity; k++)
{
@for (int i = 0; i < Model.Columns.Capacity; i++)
{
@Html.TextBox("name" + k + i, null, new { @class = "form-control" })
}
}
}
Once you have these, you can use them to work out how many iterations to do and the input names to query:
[HttpPost]
public ActionResult Enter(FormCollection form)
{
var data = new List>();
var rows = int.Parse(form["rows"]);
var columns = int.Parse(form["columns"]);
for (var r = 0; r < rows; r++)
{
var rowData = new List();
for (var c = 0; c < columns; c++)
{
rowData.Add(form[string.Format("name{0}{1}", r, c)]);
}
data.Add(rowData);
}
return View(data);
}