What I want to do it's simple. I have a view that receives a model that contains 2 lists of 2 entities. I want to pass one of that lists to controller, when I call it. It sounds simple, and I already tried various solution proposed, but can't get this to work. Also I'm new to MVC.
The Model
public class SorteioEspecial
{
RepositoryService service = new RepositoryService();
public SorteioEspecial()
{
funcionario = new List<Funcionario>();
ponderacaoFuncionario = new List<PonderacaoFuncionario>();
}
public IEnumerable<Funcionario> funcionario { get; set; }
public IEnumerable<PonderacaoFuncionario> ponderacaoFuncionario { get; set; }
public IEnumerable<Funcionario> GetFuncionarios()
{
funcionario = service.GetFuncionarios();
return funcionario;
}
public IEnumerable<PonderacaoFuncionario> GetPonderacaoFuncionario()
{
ponderacaoFuncionario = service.GetPonderacaoFuncionario();
return ponderacaoFuncionario;
}
}
The View
@model Alpd.Models.SorteioEspecial
@using (@Html.BeginForm("EditarPonderacoesEspecialSecond", "Sorteios",Model.ponderacaoFuncionario, FormMethod.Post))
{
<div class="filterbox">
<table class="table">
<tr>
<th>
<b>ID</b>
</th>
<th>
<b>ID Funcionário</b>
</th>
<th>
<b>Nome Funcionário</b>
</th>
<th>
<b>Ponderação</b>
</th>
<th>
<b>Incluir Sorteio</b>
</th>
<th></th>
</tr>
@foreach (var item in Model.ponderacaoFuncionario)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Id)</td>
<td>@Html.DisplayFor(modelItem => item.Funcionario)</td>
<td>@Html.DisplayFor(modelItem => item.Nome_Funcionario)</td>
<td>@Html.DisplayFor(modelItem => item.Ponderacao)</td>
<td>@Html.DisplayFor(modelItem => item.Incluir_sorteio)</td>
</tr>
}
</table>
</div>
<!--
<div class="col-md-10">
<a href='Url.Action("EditarPonderacoesEspecialSecond", "Sorteios", Model.ponderacaoFuncionario)'>
<input type="submit" value="Editar Ponderações" class="btn-default" />
</a>
</div>
-->
@Html.HiddenFor(model => model.ponderacaoFuncionario)
@Html.EditorFor(model => model.ponderacaoFuncionario)
<input type="submit" value="Editar Ponderações" class="btn-default" />
}
The controller method
[HttpPost]
public ActionResult EditarPonderacoesEspecialSecond (SorteioEspecial pf)
{
return View(pf);
}
I just want to call the method, passing the list of entities ponderacaoFuncionario . Dont want to do anything on the view (just show the table). Also if I am not doing this by the proper way, can you give an advice of how to do it?