2
I basically have a Controller
who sends a iList
to the View
, that one View
could edit any record of that iList
, but when the Controller
receives it is 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 a @Html.Beginform inside for..
and then I did it on 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);
}
Because the EP is coming empty? should I receive it as iList? but I just need a record..
but this action would not conflict with what I already have, after all both receive an int Index(int variable)
– Dorathoto
and this Hiddenfor with (m => m) inside my for does not find nda...would be Model.Idestagioprocess ?
– Dorathoto