:net core pasar modelo del grid al metodo POST
Publicado por Rodrigo prada (3 intervenciones) el 03/02/2021 01:06:39
BUenas Noches
En este momento estoy intentando pasar el modelo de la grilla al post basado en los checkbox que se seleccionen.
Hay dos modelos
ROLES
MENU
BIGMODEL
VISTA
CONTROLER
En el get carga la tabla sin problemas pero en el post solo esta llenando el modelo del role mas no el del menu.
Adjunto imagen de la pantalla

En este momento estoy intentando pasar el modelo de la grilla al post basado en los checkbox que se seleccionen.
Hay dos modelos
ROLES
1
2
3
4
5
6
7
8
9
10
public class CreateRoleViewModel
{
[BindProperty]
[Display(Name = "RoleId")]
public string Id { get; set; }
[Display(Name = "AreaId")]
public int AreaId { get; set; }
...
}
MENU
1
2
3
4
5
6
7
8
9
public class MenuMasterViewModel
{
[Display(Name = "Seleccion")]
public bool SelectItem { get; set; }
[Display(Name = "ID")]
public int MenuId { get; set; }
...
}
BIGMODEL
1
2
3
4
5
public class BigMenuVSRoleViewModel
{
public CreateRoleViewModel CreateRoleViewModel { get; set; }
public List<MenuMasterViewModel> MenuMasterViewModel { get; set; } = new List<MenuMasterViewModel>();
}
VISTA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@using (Html.BeginForm("CrearRoles", "RoleController"))
@model BigMenuVSRoleViewModel;
@{
ViewData["Title"] = "Creacion de Roles";
}
<h1>@ViewData["Title"]</h1>
<div class="row">
<div class="col-md-4">
<hr />
</div>
</div>
<form method="post">
<div class="row">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="col">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-university" aria-hidden="true"></i></span>
</div>
<select asp-for="@Model.CreateRoleViewModel.AreaName" asp-items="@(new SelectList(@ViewBag.areaLista, "Text", "Text"))" class="form-control" aria-describedby="Val1">
<option value="">Seleccione el Area</option>
</select>
<span asp-validation-for="@Model.CreateRoleViewModel.AreaName" class="input-group-text" id="Val1"></span>
</div>
</div>
<div class="col">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-users" aria-hidden="true"></i></span>
</div>
<input type="text" asp-for="@Model.CreateRoleViewModel.RoleName" class="form-control" placeholder="Nombre del Rol" aria-label="Nombre del Rol" aria-describedby="Val2">
<div class="input-group-prepend">
<span asp-validation-for="@Model.CreateRoleViewModel.RoleName" class="input-group-text" id="Val2"></span>
</div>
</div>
</div>
<div class="col">
<button id="SendMenu" type="submit" class="btn btn-primary">Crear Role</button>
<a asp-area="Management" asp-controller="Role" asp-action="Roles" class="btn btn-danger">Cancelar</a>
</div>
</div>
<hr />
<table class="table table-striped" id="tblMenu">
<thead class="thead-dark">
<tr>
<th>Check</th>
<th>Area</th>
<th>Ruta</th>
<th>Nombre</th>
<th>Titulo</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.MenuMasterViewModel)
{
<tr>
<td class="SelectItem">
@Html.CheckBoxFor(modelItem => item.SelectItem)
@Html.HiddenFor(modelItem => item.MenuId)
</td>
<td>
@Html.DisplayFor(modelItem => item.AreaName)
</td>
<td>
@Html.DisplayFor(modelItem => item.MenuPath)
</td>
<td>
@Html.DisplayFor(modelItem => item.MenuName)
</td>
<td>
@Html.DisplayFor(modelItem => item.MenuTitle)
</td>
</tr>
}
</tbody>
</table>
</form>
CONTROLER
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[HttpGet]
public async Task<IActionResult> CrearRoles()
{
SessionViewModel sesion = HttpContext.Session.Get<SessionViewModel>("Session");
ViewBag.areaLista = _area.GetListAreas(sesion.AreaId);
BigMenuVSRoleViewModel model = new BigMenuVSRoleViewModel();
{
model.MenuMasterViewModel = _roles.GetRolesVSMenu(sesion.AreaId);
}
return View(model);
}
[HttpPost]
public async Task<IActionResult> CrearRoles([FromBody] BigMenuVSRoleViewModel BigMenuVSRoleViewModel)
{
SessionViewModel sesion = HttpContext.Session.Get<SessionViewModel>("Session");
ViewBag.areaLista = _area.GetListAreas(sesion.AreaId);
}
En el get carga la tabla sin problemas pero en el post solo esta llenando el modelo del role mas no el del menu.
Adjunto imagen de la pantalla

Valora esta pregunta


0