Get post data in ASP.Net MVC

1

I'm using MVC in my application and in Views I'm using various Telerik tools.

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

Follow 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>

Follow Controller:

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

    return RedirectToAction("Index");
}

With this code I get the values of the checkedCli array, but I would also like to get the values from the YEAR MONTH column of the Grid. I can not particularly explain why checkedCli data collection works, I suppose it is the name attribute that references POST, indicating that it is the checkedCli from Controller.

How do I also get the values from the YEAR MONTH column?

    
asked by anonymous 14.02.2014 / 20:24

2 answers

1

You need to create input type="hidden" fields with the values you want to be passed via POST , and create in the action a parameter with the same name that is in 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");
}
    
14.02.2014 / 22:39
0

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

    
14.02.2014 / 20:30