0

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>
9
  • where is your issue pleae be spsific, you want to submit data and recive it as array of integers ? or you submitting something null ? Commented May 5, 2019 at 13:54
  • Anyway please put your detailed code Commented May 5, 2019 at 13:54
  • @Mohammad Alghanem Hi, thank you for response. The problem is that on clicking submit button the method SubmitForm gets NULL model(Matrix class). I Commented May 5, 2019 at 14:05
  • @Mohammad Alghanem I've added piece of code from form,hope now it is clearer now Commented May 5, 2019 at 14:12
  • try use EditorFor not Display for and let me know Commented May 5, 2019 at 14:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.