I want to bind array from view to process it in controller method.
HTML generated
Model
public class Matrix
{
public int[,] Numbers { get; set; }
}
View @model Project.Models.Matrix
@{
var options = new AjaxOptions()
{
UpdateTargetId = "Matrix",
};
}
@using (Ajax.BeginForm("Form", "Home", FormMethod.Post, options))
{
<div id="Matrix"> </div>
<input type="submit" value="Rotate" name="ButtonType" />
}
partial view
@model int[,]
@if (Model != null && Model.Length > 0)
{
<table id="numbers-container">
@for (int column = 0; column < Model.GetLength(0); column++)
{
<tr>
@for (int row = 0; row < Model.GetLength(1); row++)
{
var Numbers= Model[column, row];
@Html.TextBoxFor(m => Numbers, new { id = $"{column}_{row}" })
}
</tr>
}
</table>
}
controller
[HttpPost]
public ActionResult SubmitForm(Matrix model, string ButtonType)
If I add some simple property ,it is filled in model, but array is null, MVC doesnot want to bind it because of ids and names in generated html are the same.How to change it to get filled array from form in controller? Need any help