I basically have a Controller
that sends iList
to View
, this View
could edit any record of this iList
, however when Controller
receives it already empty.
I did so:
Controller:
public ActionResult Index(int id)
{
var epClientes = db.EstagioProcess
.Include(etapa => etapa.Cliente)
.GroupBy(etapa => etapa.ClienteId)
.Where(grupo => grupo
.OrderByDescending(etapa => etapa.EpId).Take(1)
.Select(etapa => etapa.EP)
.FirstOrDefault() == 2);
var EP = new List<EstagioProcesso>();
foreach (var epCliente in epClientes)
{
EP.AddRange(epCliente);
}
return View(EP);
}
View:
@model IList<WMB.MVC.Extranet.Models.EstagioProcesso>
<table class="table">
<tr>
<th>URL</th>
<th>EP</th>
<th>Data</th>
<th>ID Funcionário</th>
<th></th>
</tr>
@for (var i = 0; i < Model.Count; i++)
{
using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<tr>
<td>
@Html.DisplayFor(x => x[i].ClienteId)
</td>
<td>
@Html.DisplayFor(x => x[i].EP)
</td>
<td>
@Html.DisplayFor(x => x[i].Data)
</td>
<td>
@Html.DisplayFor(x => x[i].IdFuncionario)
</td>
<td>
<input type="submit" value="Gravar" class="btn btn-default" />
</td>
</tr>
}}
</table>
See that I put an @ Html.BeginForm inside the for ..
and then I made the controller to receive
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(EstagioProcesso EP)
{
//EP Está vazio..não recebe, nda
EP.EP = Convert.ToByte(Request.Form["Sel_EP"]);
if (ModelState.IsValid)
{
db.EstagioProcess.Add(EP);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(EP);
}
Why the EP is coming empty? Should I get it as an iList? but I just need a registry ..