I can't get the values in controller from the post method used on the view and I don't know why. I saw a lot of forums and I thought that I was doing the right thing, but it doesn't seem to be the correct way to do because I can't get the values.
First I was using just the DisplayFor
but that just shows and not pass the values then I join the HiddenFor
to use that like an input like I saw in other forums. But the model always returns zero values.
AtribuiçãoController:
public IActionResult Create(List<Main> main)
{
return RedirectToAction(nameof(Index));
}
Index.cshtml:
@model ModelsLibrary.Main
<form asp-action="Create">
<table class="table">
<thead>
<tr>
<th>
<label>Disciplina</label>
</th>
<th>
<label>Turno</label>
</th>
<th>
<label>Tipologia</label>
</th>
<th>
<label>Docente</label>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Turno)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.MetaDisciplina.Nome)
@Html.HiddenFor(modelItem => item.MetaDisciplina.Nome)
</td>
<td>
@Html.DisplayFor(modelItem => item.LetraTurno)
@Html.HiddenFor(modelItem => item.LetraTurno)
</td>
<td>
@Html.DisplayFor(modelItem => item.Tipologia.Tipo)
@Html.HiddenFor(modelItem => item.Tipologia.Tipo)
</td>
<td>
<select asp-for="Docente" asp-items="ViewBag.Docente"></select>
</td>
</tr>
}
</tbody>
</table>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
Index Method
[HttpGet]
public IActionResult Index()
{
var Turno = new List<Turno>();
Main main = new Main();
main.Turno = Turno;
ViewData["Ano"] = new SelectList(_context.AnoLetivo, "Ano", "Ano");
return View(main);
}
Hi have a problem binding the values to the controller. The method create should get values in the attributes but i don't know why and heaven don't know why the values not pass... I not pass a list to the view but i want one list in the create method.... If someone can help.