Get Post Data in ASP.Net MVC

Asked

Viewed 1,994 times

1

I’m using MVC in my application and in Views I am using several tools from Telerik.

I need to get some information from a POST that I give in mine View.

Segue View:

<div class="div-grid">
@using (Html.BeginForm("ExecutaExportacao", "ExportacaoFinal"))
{
    @(Html.Telerik().Grid(listRateioFinal)
          .Name("Grid")
          .Columns(columns =>
          {
              columns.Template(
                  @<text>
                       <input name="checkedCli" type="checkbox" value="@item.Row.ItemArray[1].ToString()" title="checkedCli" />
                  </text>).Title("").Width(10).HtmlAttributes(new { style = "text-align:center" });
              columns.Bound(o => o.Row.ItemArray[0]).Width(100).Title("ANO MES");
              columns.Bound(o => o.Row.ItemArray[1]).Width(100).Title("ID_CLI");
              columns.Bound(o => o.Row.ItemArray[2]).Width(100).Title("VALOR");
          })
          .Scrollable())
    <input type="submit" value="Exportar Arquivo"/>
}
</div>

Segue Controller:

[HttpPost]
public ActionResult ExecutaExportacao(int[] checkedCli)
{
    ExportarArquivo(anoMes);

    return RedirectToAction("Index");
}

With this code I get the values of the array checkedCli, but would also like to get the column values MONTH YEAR Grid. I particularly can’t explain why it works to obtain data from checkedCli, I suppose it’s the attribute name which refers to the POST, indicating that it is the value of the parameter checkedCli controller’s.

How do I also get the column values MONTH YEAR ?

  • That instruction: columns.Bound(o => o.Row.ItemArray[0]).Width(100).Title("ANO MES"); generates a form field?

  • You could add to the question which HTML is generated by the component you are using?

2 answers

1


You need to create fields input type="hidden" with the values you want them to be passed via POST, and create a parameter with the same name in the action name of this input:

@(Html.Telerik().Grid(listRateioFinal)
      .Name("Grid")
      .Columns(columns =>
      {
          columns.Template(
              @<text>
                   <input name="checkedCli" type="checkbox" value="@item.Row.ItemArray[1].ToString()" title="checkedCli" />
              </text>).Title("").Width(10).HtmlAttributes(new { style = "text-align:center" });
          columns.Template(
              @<text>
                   <input name="anoMes" type="hidden" value="@item.Row.ItemArray[0].ToString()" title="ANO MES" />
              </text>).Width(100).Title("ANO MES");
          columns.Bound(o => o.Row.ItemArray[1]).Width(100).Title("ID_CLI");
          columns.Bound(o => o.Row.ItemArray[2]).Width(100).Title("VALOR");
      })

Action:

[HttpPost]
public ActionResult ExecutaExportacao(int[] checkedCli, string[] anoMes)
{
    ExportarArquivo(anoMes);

    return RedirectToAction("Index");
}

0

Just create an object(template) containing the properties with the same view name, as in your example this object will have a property called checkedCli

Browser other questions tagged

You are not signed in. Login or sign up in order to post.