Briefly:
I have a screen with a table
populated by the list below, where I select the line through checkbox
, I need to pass that list to my actionResult
.
As I do not have a form on this screen I can not give the data to pass to actionResult
.
ViewModel used in html with property list
public class DeliveryServiceListViewModel
{
public List<DeliveryServiceViewModel> DeliveryServices { get; set; }
}
ActionResult
:
public ActionResult EditAll()
{
}
What I call that way I do not know if it's the right one:
<button onclick="location.href='@Url.Action("EditAll", "DeliveryService")'">
Salvar
</button>
- How to pass the list so I can deal with
controller
? - Is there any way I can just pass the list or do I have to pass all the ViewModel that contains the list?
I tried to pass the list using new { DeliveryServices = Model.DeliveryServices }
, but it arrives at controller
empty.
@model Dlieve.BackOffice.Areas.BackOffice.Models.DeliveryServiceListViewModel
<table class="table-long" id="deliveries">
<tr>
<th>Portador</th>
<th>Cliente</th>
<th>Data de Cadastro</th>
<th>Descrição</th>
<th>Status</th>
<th>Motivo Entrega Não Realizada</th>
<th><input type="checkbox" id="selectAllCheckBoxes" /></th>
<th colspan="4">
<div class="btnSituacao" hidden>
<button onclick="enviarFormulario()">Salvar</button>
<button id="cancel">Cancelar</button>
</div>
</th>
<th></th>
@if (Model != null)
{
for (int i = 0; i < Model.DeliveryServices.Count; i++)
{
var checkboxChecked = Model.DeliveryServices[i].IsSelected;
<tr>
<td>@Html.DisplayFor(modelItem => carrierFullName)</td>
<td>@Html.DisplayFor(modelItem => shipperCustomerFullName)</td>
<td>@Html.DisplayFor(modelItem => Model.DeliveryServices[i].Created)</td>
<td>@Html.DisplayFor(modelItem => Model.DeliveryServices[i].Description)</td>
<td>@Html.DisplayFor(modelItem => Model.DeliveryServices[i].DeliveryServiceStatusModel.Description)</td>
<td>@Html.DisplayFor(modelItem => Model.DeliveryServices[i].NonDeliveryDescription)</td>
@*declaração de variavel local para simplificar o tratamento condicional de "description"*@
@{var description = Model.DeliveryServices[i].DeliveryServiceStatusModel.Description;}
@if (description == "Em Andamento" || description == "Roteirizado")
{
<td>@Html.CheckBoxFor(modelItem => Model.DeliveryServices[i].IsSelected)</td>
}
else
{
<td></td>
}
}
}
</table>