Reputation: 53
I have to select rows from a table and then I have to send it to my data base in SQL SERVER to process that data. I thought that I can save this selected items into a JSON string and then the Stored Procedure can receive that string.
I have this in my .cshtml file:
@model List<model.entity.Recibo>
@{
ViewBag.Title = "Recibos Pendientes";
}
<h2>RecibosPendientes</h2>
<div class="container-fluid">
<table class="table">
<tr class="btn-success">
<th></th>
<th>ID Recibo</th>
<th>Fecha</th>
<th>Concepto de Cobro</th>
<th>Seleccionar</th>
</tr>
@foreach (var objetoRecibo in Model)
{
<tr>
<td><a class="btn btn-info" href="~/Recibo/ReciboPendiente/@objetoRecibo.IdRecibo">Ver</a></td>
<td>@objetoRecibo.IdRecibo</td>
<td>@objetoRecibo.FechaEm</td>
<td>@objetoRecibo.NombreCC</td>
<td><input name="RecibosMarcados" type="checkbox" value="False" /> </td>
</tr>
}
</table>
<button type="button" class="fa-cc-visa" onclick="">Pagar</button>
</div>
I am not pretty sure how to save the selected ID columns and save it into a JSON string when I press the Pagar button.
Upvotes: 1
Views: 851
Reputation: 5895
Use a <Form>
tag, and the id that you want to send should be put in a hidden input. e.g.
<input type="hidden" name="IdRecibo[@objetoRecibo.IdRecibo]" value="@objetoRecibo.IdRecibo">
The name is made unique by having an array notation in the name attribute. You need to have a method to deal with the form post request as well. I suggest having a read about that in an asp.net book or microsoft's documentation.
Upvotes: 1