gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:07:46 26 4
gpt4 key购买 nike

如何在不使用局部 View 的情况下在模态弹出窗口中显示数据表。听说是我的 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 -->

听说我正在使用/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>

弹出模态部分

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

方法

[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 是我的部分 View ,那里没有内容。我想在不调用部分 View 的情况下将数据加载到模态对话框

最佳答案

所以...只需将 Modal 放在父页面上,并在其中定义表格。不需要模态。 但是该表将在父页面填充时填充。

将您的按钮 html 更改为

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

关于c# - 带有数据表的 asp.net mvc 模式弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42570715/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com