I have a viewmodel called Profile, in this viewmodel there is a ListProperties property and a string - title.
public class PerfilViewModel
{
[Key]
[DisplayName("Código")]
public int Id { get; set; }
[Required(ErrorMessage = "O campo {0} é obrigatório")]
[StringLength(50, ErrorMessage = "O campo {0} deve ter no mímino {1} caracteres")]
[DisplayName("Título")]
public string Titulo { get; set; }
public IEnumerable<PerfilItens> ItensPerfil { get; set; }
}
The attributes of the ProfileStyle class are boolean: view, create, edit, and delete, and one more (id) that indicates the Profile of this ProfilePart. I create my view this way:
var viewModel = new PerfilViewModel();
var itens = Bootstrap._listaPerfil;
viewModel.ItensPerfil = itens.Select(x => new PerfilItensViewModel
{
ItemMenu = x.ItemMenu,
Criar = x.Criar,
Visualizar = x.Visualizar,
Excluir = x.Excluir,
Editar = x.Editar
});
return View(viewModel);
The Bootstrap.ListPath () function only loads the profile items that should be created. The view appears perfectly, through a for or foreach to generate the user of the profile items, it just needs to insert a title and check or not, via checkbox, the items.
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Descricao" class="control-label"></label>
<input asp-for="Descricao" class="form-control" />
<span asp-validation-for="Descricao" class="text-danger"></span>
</div>
@foreach (var item in Model.ItensPerfil)
{
<hr />
<div class="form-group">
<label id="menu" class="control-label">@item.ItemMenu</label>
</div>
<div class="form-group">
<label asp-for="@item.Visualizar" class="control-label"></label>
<input type="checkbox" asp-for="@item.Visualizar" checked="@item.Visualizar" />
<label asp-for="@item.Editar" class="control-label"></label>
<input type="checkbox" asp-for="@item.Editar" checked="@item.Editar" />
<label asp-for="@item.Criar" class="control-label"></label>
<input type="checkbox" asp-for="@item.Criar" checked="@item.Criar" />
<label asp-for="@item.Excluir" class="control-label"></label>
<input type="checkbox" asp-for="@item.Excluir" checked="@item.Excluir" />
</div>
}
<hr />
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
Now we go to the problem, when it returns to the Create function by Post the Profile comes correctly, the title appears right, but the Profile items returns as null. Any solution for this?