I\'m trying to edit a list of items in a strongly-typed razor view. The templates don\'t give me the option to edit a list of objects in a single view so I merged the List v
How do i do it? FormCollection? Viewdata?
None of the above, use the view model:
[HttpPost]
public ActionResult EditPermissoes(IEnumerable model)
{
// loop through the model and for each item .HasPermissao will contain what you need
}
And inside your view instead of writing some loops use editor templates:
Indicador
Nome
Descrição
@Html.EditorForModel()
and inside the corresponding editor template (~/Views/Shared/EditorTemplates/Permissao.cshtml
):
@model Permissao
@Html.CheckBoxFor(x => x.HasPermissao)
@Html.DisplayFor(x => x.TipoP.IndID)
@Html.DisplayFor(x => x.TipoP.Nome)
@Html.DisplayFor(x => x.TipoP.Descricao)