以向导形式传递数据而不在MVC中回发

时间:2018-03-25 11:39:08

标签: javascript jquery asp.net-mvc twitter-bootstrap twitter-bootstrap-wizard

对不起任何错误。我是MVC的新手。我想在单个视图中将数据从一个向导表单传递给另一个。下面是我的控制器端代码,它返回要查看的列表。在视图中有向导表单,我在列表中更新一些字段,在下一个按钮上我想将所有更改的数据传递到表格中的下一个向导表单。

public ActionResult PlaceOrder()
{
 OrderDetail ObjOrderDetails = new OrderDetail();
 try
  {
     DataSet ds = new DataSet();
     ds = GeneralHelper.GetUserDocumentDetail(1);
     List<OrderModel> objOrder = ds.Tables[0].ToList<OrderModel>();
     ObjOrderDetails.OrderDetails = objOrder;
   }
   catch (Exception ex)
   {               
            throw ex;
   }
     return View(ObjOrderDetails);
 }

以下是我的观点代码

 <div class="tab-content">
    <div class="tab-pane" id="details">
        <div class="row">
            <div class="col-sm-12">
            <h4 class="info-text">
                Let's start with the basic details.</h4>
        </div>
        <div class="form-horizontal">
            <div class="form-group">
                <div class="col-md-12">
                    <div class="persons">
                        <table class="table table-condensed table-hover" id="tblPurchaseOrders">
                            <tr>
                                <th>
                                    Product Code
                                </th>
                                <th>
                                    SKU
                                </th>
                                <th>
                                    Product Name
                                </th>
                                <th>
                                    Quantity
                                </th>
                            </tr>
                            @{ 
                            //To make unique Id int i = 0; 
                            foreach (var item in Model.OrderDetails.ToList())
                            {
                            <tr>
                                <td>
                                    @Html.EditorFor(o => o.OrderDetails[i].ProductCode, new { htmlAttributes = new { @class = "form-control", disabled = "disabled", @readonly = "readonly" } })
                                </td>
                                <td>
                                    @Html.EditorFor(o => o.OrderDetails[i].SKU, new { htmlAttributes = new { @class = "form-control", disabled = "disabled", @readonly = "readonly" } })
                                </td>
                                <td>
                                    @Html.EditorFor(o => o.OrderDetails[i].Name, new { htmlAttributes = new { @class = "form-control", disabled = "disabled", @readonly = "readonly" } })
                                </td>
                                <td>
                                    @Html.EditorFor(o => o.OrderDetails[i].Quantity, new { @id = "Quantity_" + i })
                                </td>
                            </tr>
                            i++; } }
                        </table>
                    </div>
                </div>
            </div>
            <hr />

        </div>
    </div>
</div>
<div class="tab-pane" id="captain">
    <div class="row">
        <div class="form-group">
            <div class="col-md-12">
                <table class="table table-condensed table-hover" id="tbOrderDetail">
                    <tr>
                        <th>
                            Product Code
                        </th>
                        <th>
                            SKU
                        </th>
                        <th>
                            Product Name
                        </th>
                        <th>
                            Quantity
                        </th>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>

下面是我的jquery代码。

$('#rootwizard').bootstrapWizard({
    onTabShow: function(tab, navigation, index) {
        if (index == 1) {

            $(".persons > table").each(function() {

                var fields = $(this).find(":text");
                alert(fields)
                var name = fields.eq(-1).val();
                var age = fields.eq(1).val();
                alert(name);
            });


        }

    }
}); 

我想循环#tblPurchaseOrders的所有行,并希望将所有行追加到#tbOrderDetail,其中数量大于0.

1 个答案:

答案 0 :(得分:1)

你可以这样做:

$('#rootwizard').bootstrapWizard({
    onTabShow: function(tab, navigation, index) {
        if (index == 1) {
            $('#tblPurchaseOrders').find('tr:has(td)').each(function() {
                if (parseInt(($(this).find('#Quantity')).val()) > 0)
                    $(this).appendTo('#tbOrderDetail');
            });
        }
    }
});

Online Demo (jsFiddle)