简体   繁体   中英

How can I select and save data row in a table? C# ASP.NET MVC 5

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>

It looks like this. 我必须选择一行的表

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.

Use a <Form> tag, and the id that you want to send should be put in a hidden input. eg

<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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM