【问题标题】:How can I select and save data row in a table? C# ASP.NET MVC 5如何在表格中选择和保存数据行? C# ASP.NET MVC 5
【发布时间】:2020-07-22 00:18:51
【问题描述】:

我必须从表中选择行,然后将其发送到 SQL SERVER 中的数据库以处理该数据。我认为我可以将这些选定的项目保存到 JSON 字符串中,然后存储过程可以接收该字符串。

我的 .cshtml 文件中有这个:

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

看起来像这样。

当我按下 Pagar 按钮时,我不太确定如何保存选定的 ID 列并将其保存为 JSON 字符串。

【问题讨论】:

    标签: c# asp.net sql-server asp.net-mvc


    【解决方案1】:

    使用&lt;Form&gt; 标记,并且您要发送的 id 应放在隐藏输入中。例如

    <input type="hidden" name="IdRecibo[@objetoRecibo.IdRecibo]" value="@objetoRecibo.IdRecibo">
    

    通过在 name 属性中使用数组表示法,该名称是唯一的。您还需要有一种方法来处理表单发布请求。我建议在 asp.net 书籍或microsoft's documentation 中阅读有关该内容的内容。

    【讨论】:

      猜你喜欢
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多