简体   繁体   English

带有数据表的asp.net mvc模式弹出窗口

[英]asp.net mvc modal popup with datatable

How to Display a Datatable in Modal Popup with out using partial view. 如何在模式弹出窗口中不使用部分视图显示数据表。 hear is the my indax.cshtml 听说是我的indax.cshtml

<button type="button" class="btn btn-info btn-infolink btn-BranchNetwork">Branch Network</button>


<div class="modal fade" id="itemModel" 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"> Branch Network</h4>
        </div>
        <div class="modal-body no-padding">
            <div style="width:100%; margin:0 auto;">
                <table id="branchTable">
                    <thead>
                        <tr>
                            <th>BranchName</th>
                            <th>Address</th>
                            <th>Manager Name</th>
                            <th>Mobile</th>
                            <th>Telephone</th>
                            <th>fax</th>
                        </tr>
                    </thead>
                </table>
            </div>
            <style>
                tr.even {
                    background-color: #F5F5F5 !important;
                }
            </style>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

hear i'm using /Branch/GetBranchNetwork for getting Data. 听说我正在使用/ Branch / GetBranchNetwork来获取数据。

@section Scripts{    
<script>        
    $(document).ready(function () {
        $('#branchTable').DataTable({
            "processing": true, // for show progress bar
            "ajax": {
                cache: false,
                url: "/Branch/GetBranchNetwork",
                type: "POST",
                datatype: "json",
            },
            "columns": [
                { "data": "branchName", "width": "5%", },
                { "data": "address"},
                { "data": "managerName"},
                { "data": "mobile"},
                { "data": "telephone"},
                { "data": "fax"},
            ]
        });
    });
</script>

} }

popup Modal section 弹出模态部分

<script>
$('.btn-BranchNetwork').on('click', function () {
    var url = '/Branch/BranchNetwork';
    $.get(url, function (data) {
        //debugger;
        $('#ItemModelContent').html(data);
        $('#itemModel').modal('show');
    });
});

Method 方法

[HttpPost]
    public ActionResult GetBranchNetwork()
    {
        WebPortalEntities db = new WebPortalEntities();
        var jsonData = new
        {
            data = from a in db.tbl_branchNetwork.ToList() select a
        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }




public ActionResult BranchNetwork()
    {
        return PartialView("_BranchNetwork");
    }

_BranchNetwork.cshtml is my Partial view and no content there. _BranchNetwork.cshtml是我的部分视图,那里没有内容。 i want to without calling partial view.load data to modal dialog 我想不调用局部view.load数据到模式对话框

So... just put the Modal on the parent page with the table defined in it. 所以...只需将Modal放在其中定义了表的父页面上即可。 No need for modal. 无需模态。 BUT the table will populate when the parent page populates. 但是当父页面填充时,表格将被填充。

change your button html to 将您的按钮html更改为

<button type="button" class="btn btn-info btn-infolink btn-BranchNetwork" 
 data-toggle="modal" data-target="#itemModel">Branch Network</button>

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

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