vendredi 13 février 2015

How to return to the View the items checked by the CheckBox?

I am developing a project in ASP.net MVC. In my registration form, I have a checkbox where I select the items you would like to add to the database. My form of editing, I have to get these checked items and show the view: all items that are in the grid and the fields that were selected are saved in the database. I would like to return to the View all checked items that are saved in the database.


The code looks like this:



@using Forte.Rastreador.ViewModels
@using GridMvc.Html

@model SuperModulosPerfilUsuarioViewModel

<fieldset>
@Html.Label("Nome do Perfil: ")
@Html.TextBoxFor(u => u.Descricao)
<br /><br />
</fieldset>

<fieldset> //minha checkBOX
<legend>Modulos do Sistema</legend>

@Html.Grid(Model.ModulosSistemas).Columns(columns =>
{
columns.Add()
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(o => Html.CheckBox("Checked", @Model.Check, new { value = o.CodModulo }));

columns.Add(u => u.DesModulo)
.Titled("Modulos Perfil")
.Encoded(false);
})







//Action metodo get Editar, onde retorna todo o conteudo de visualizacao para a view.
public ActionResult EditarPerfilUsuario(int CodPerfil)
{

var perfilUsuario = PerfilUsuarioRepositorio.ObterPerfilUsuarioPorCodigo(CodPerfil);
var perfilUsuarioVM = new SuperModulosPerfilUsuarioViewModel();
perfilUsuarioVM.Descricao = perfilUsuario.Descricao;
perfilUsuarioVM.ModulosSistemas = ModulosSistemaRepositorio.ListarModulosSistemas();
perfilUsuarioVM.ModulosDoPerfil = ModulosPerfilRepositorio.ListarModulosDoPerfisPorCodPerfil(CodPerfil);

foreach (var ms in perfilUsuarioVM.ModulosSistemas)
{
foreach (var mp in perfilUsuarioVM.ModulosDoPerfil)
{
if (ms.CodModulo == mp.CodModulo)
{
perfilUsuarioVM.Check = true;
}
}
}

return View("EditarPerfilUsuario", perfilUsuarioVM);
}

public IEnumerable<ModulosSistema> ListarModulosSistemas() //metodos listar que se encontram no meu repositorio
{
return this.Context.ModulosSistemas;
}

public IEnumerable<ModulosDoPerfil> ListarModulosDoPerfisPorCodPerfil(int CodPerfil)
{
return this.Context.ModulosDoPerfil.Where(c=>c.CodPerfil==CodPerfil);
}




Aucun commentaire:

Enregistrer un commentaire