I have form with several input buttons. Within this forms buttons can do actions. With 1st button I generate table(object with property of type int[,]). With the 2nd button I am going to do smth with this object. The first is ok, the 2nd returns null for model to controller. How to pass from form this object with array inside to controller? Now in SubmitForm method I have value for buttonType, but matrix is null(should be data from table).Appreciate any help
Model
public class Matrix
{
public int[,] Data { get; set; }
}
Controller
[HttpPost]
public ActionResult SubmitForm(Matrix matrix, string ButtonType) - matrix is NULL here, how to get info from form
{
if (ButtonType == "Rotate")
{
return RotateMatrix(matrix);
}
//other code
}
[HttpPost]
public ActionResult RotateMatrix(Matrix matrix)
{
//-some code
return PartialView("_MatrixView", matrix);
}
View
@model Project.Models.Matrix
@{
ViewBag.Title = "Home Page";
var options = new AjaxOptions()
{
UpdateTargetId = "Matrix",
};
}
@using (Ajax.BeginForm("SubmitForm", "Home", FormMethod.Post, options))
{
<div id="Matrix"></div>
<input type="submit" value="Rotate" name="ButtonType" />
<input type="submit" value="Generate" name="ButtonType"/>
}
PartialView
@model Project.Models.Matrix
<table>
@for (int column = 0; column < Model.Data.GetLength(0); column++)
{
<tr>
@for (int row = 0; row < Model.Data.GetLength(1); row++)
{
var item = Model.Data[column, row];
<td>@Html.DisplayFor(m => item)</td>
}
</tr>
}
</table>