首页 > 解决方案 > 如何使用引导模型对话框将数据添加到数据表?

问题描述

如何使用模型对话框动态地将数据添加到 jquery 数据表而不在 mvc 中保存和返回视图?

 <button type="button" class="btn btn-default btn-md" data-toggle="modal" data-url="@Url.Action("Create","POPM_Trn_IOU_Items")" id="btnCreateAsset">
                        <span class="glyphicon glyphicon-new-window" aria-hidden="true"></span> Add Asset
                    </button>


    <div class="glyphicon-modal-window" id="createAssetModal" tabindex="-1" role="dialog" aria-labelledby="CreateAssetModal" aria-hidden="true" data-backdrop="static">

        <div id="createAssetContainer">

        </div>
    </div>     
                    @*<table id="example" class="table table-striped table-bordered" cellspacing="0">*@
                    <thead>
                        <tr>
                            <th>Item</th>
                            <th>Unit</th>

                            <th>Quantity</th>
                            <th>Cost</th>                               
                            <th></th>
                            <th></th>


                        </tr>
                    </thead>
                    <tbody>
                        @if (Model.IouItems != null)
                        {
                            foreach (var item in Model.IouItems)
                            {
                            <tr>
                                <td></td>   
                                <td style="text-align:center">
                                    @Html.DisplayFor(modelItem => item.POPM_Item_ItemName)

                                </td>

                                <td style="text-align:center">
                                    @Html.DisplayFor(modelItem => item.POPM_Item_ItemUnit)
                                </td>
                                <td style="text-align:center">
                                    @Html.DisplayFor(modelItem => item.POPM_Item_Quantity)

                                </td>

                                <td style="text-align:center">
                                    @Html.DisplayFor(modelItem => item.POPM_Item_ItemCost)
                                </td>

                                <td style="text-align:center">
                                    @Html.DisplayFor(modelItem => item.Item_ID)
                                </td>


                </table>

        </div>

JS `$(document).on('click', '#btnCreateAsset', function () { var url = $(this).data("url"); $.get(url, function(data) { $( '#createAssetContainer').html(数据);

                event.preventDefault();
                jQuery.noConflict();
                var myBookId = $(this).data('k');
                $(".modal-body #a").val(myBookId);
                $('#createAssetModal').modal('show');
            });
        });``

标签: jqueryasp.net-mvcdatatablesmodal-dialog

解决方案


推荐阅读