繁体   English   中英

我如何在 Asp.net MVC 中使用复选框从数据库中获取 select 数据?

[英]How can i select data from a Database with checkbox in Asp.net MVC?

抱歉,我是 asp.net 和 MVC 的新手。 我有一个程序,它从数据库中读取数据并在索引页中显示结果,每行附近都有一个复选框:

<table class="table">
    <tr>
        <th>
            Select
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Rep_Id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Rep_Lot_Id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Rep_PDFToCreate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Rep_PDFCreated)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Rep_Status)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Rep_Type)
        </th>

    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.CheckBox("pdf", true)

            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Rep_Id)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Rep_Lot_Id)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Rep_PDFToCreate)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Rep_PDFCreated)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Rep_Status)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Rep_Type)
            </td>

        </tr>

    }

</table>

<script>
    function Obtain_Lot() {

        var name=...
    }
</script>

我的目标是创建一个按钮,单击该按钮时,它会将项目的“model.Rep_Lot_Id”作为字符串检查。 只能检查一项。 我怎样才能做到这一点?

我通常在您的情况下使用此代码:

var checkedCheckbox = $("input:checked"); // consider only one checkbox can be checked
var repLotId = $(checkedCheckbox).parent().next().next().html(); // travel to the Rep_Lot_Id `td` and get its value.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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