【问题标题】:This table has a column with check boxs that need to select the row and send rows to another table.此表有一列带有复选框,需要选择行并将行发送到另一个表。
【发布时间】:2013-11-13 21:44:21
【问题描述】:

我需要将在“AuctionPage”中选择的线圈发送到“MyBids”页面上的另一个表。我认为最好抓住线圈ID并以这种方式传递但不知道如何?任何帮助将不胜感激。

拍卖页面-->

@model NucorPrototypes_V1.ViewModel.AuctionPage

@{

ViewBag.Title = "Index";

}

<title>Auction </title>

<div id="header" style="background-color: #008751">

    <h1 style="margin-bottom: 0; color: #FFFFFF">Secondary Coil Auction </h1>

</div>

<div id="content">

    <h2>Index</h2>

    <table id="myTable" border="3" style="background-color: #B0B0B0" cellpadding="10" class="table">

        <tr>

            <th>Select</th>

            <th>Serial Number</th>

            <th>Minimum Bid</th>

            <th>Current High Bid</th>

            <th>Grade</th>

            <th>Heat Number</th>

            <th>Gauge</th>

            <th>Width</th>

            <th>Weight</th>

            <th>Defect 1</th>

            <th>Defect 2</th>

            <th>Defect 3</th>

        </tr>

        @foreach (var item1 in Model.Coils)

        {

            <tr>

                <td>

                    <input type="checkbox" name="selection" id="@item1.Coil_ID" align="center">

                </td>

                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_ID)

                </td>

                <td>

                    @foreach (var item2 in Model.Auctions)

                    {

                        @Html.DisplayFor(modelItem => item2.Auc_MinBid)

                    }

                </td>




                <td>

                    @foreach (var item3 in Model.Bids)

                    {



                        @Html.DisplayFor(modelItem => item3.Bid_Amt)

                        //string sqlq = "select max(Bid_Amt) from Bid inner join AuctionItem ON Bid.Bid_ID = AuctionItem.Bid_ID where Coil_ID =" + item1.Coil_ID +"' '";



                    }




                </td>




                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_Grade)

                </td>

                <td>

                    <a data-toggle="modal" data-target="#myModal">@Html.DisplayFor(modelItem => item1.Coil_HeatNo)</a>

                    <!-- Modal -->

                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

                        <div class="modal-dialog">

                            <div class="modal-content">

                                <div class="modal-header">

                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

                                    <h4 class="modal-title" id="myModalLabel">@Html.DisplayFor(modelItem => item1.Coil_HeatNo)</h4>

                                </div>

                                <div class="modal-body">



                                    CHemistries

                                </div>

                            </div>

                        </div>

                    </div>

                </td>

                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_Gauge)

                </td>

                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_Width)

                </td>

                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_Weight)

                </td>

                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_Defect1)

                </td>

                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_Defect2)

                </td>

                <td>

                    @Html.DisplayFor(modelItem => item1.Coil_Defect3)

                </td>




            </tr>

        }




    </table>

    </center>

</div>

<center>

Place Bid(s)

</center>

MyBids 页面-->

@model NucorPrototypes_V1.ViewModel.MyBids

@{

ViewBag.Title = "MyBids";

}

拍卖

二次线圈拍卖 每100重量的投标金额 移除出价 序列号 最低出价 当前最高出价 年级 发热量 测量 宽度 重量 缺陷一 缺陷 2 缺陷 3 @foreach(Model.Coils 中的 var 行) { 移除出价 @Html.DisplayFor(modelItem => row.Coil_ID) }
<center>

确认出价

另存为...

</center>

【问题讨论】:

  • 当您说发送到另一个页面时。这是他们点击一行时的重定向,还是您收集他们发布和重定向时点击的所有行?
  • 行被复选框选中,然后他们单击“放置投标”按钮将行发送到“我的投标”页表。

标签: c# javascript asp.net sql asp.net-mvc-4


【解决方案1】:

为了获得多个复选框的结果,我使用 Request.Form 在你的控制器上

Request.Form["chkBoxName"].ToString();

确保每个复选框都具有相同的名称(在本例中为 chxBoxName),它会为您提供所有已选中复选框的列表。然后,您可以将这些项目添加到控制器上的下一个表并在那里重定向。希望这会有所帮助

编辑:

这将返回一个以逗号分隔的选定复选框列表。由于您想将它们添加到另一个表中,因此您需要查询数据库中的它们。

[HttpPost]
public ActionResult PostBack(){
    Model model = new Model();
    List<Bids> bids = new List<Bids>();
    List<int> result = Request.Form["chkBoxName"].ToString().split(',');
    foreach(var id in result){
        //query the database to get the record for id
        bids.add("result of query");
    }
    Model.Bids = bids;
    return RedirectToAction("Bids", bids);
}

【讨论】:

  • 那么在我的控制器中,我是否需要在其中创建一个带有此 Request.Form 的 ActionResult ?我会返回什么?感谢您的帮助,这让我有了更好的理解。
  • 是的,当您回发您的页面时,请将其放入调用的操作结果方法中。您说重定向到另一个页面,因此您将为第二页创建数据表,包括选定的行,然后重定向到那里
  • 好的,谢谢。无论如何你可以给我一个例子吗?我理解上下文只是不确定如何用代码编写它。
  • 在不了解您的代码的情况下,我无法非常准确,但这是一个示例。希望对你有帮助
  • 非常感谢。这很有帮助。
【解决方案2】:

只需将复选框放在一个子表单中,该操作将转到目标表单。我看不到该语句在您提供的 HTML 中的位置,但您可以在同一页面上有多个具有不同目标的表单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    • 2017-02-23
    • 2021-12-30
    • 1970-01-01
    • 2020-09-30
    • 2015-08-16
    • 2014-01-18
    相关资源
    最近更新 更多