首页> C#> DataTables标题显示为一行? MVC Asp.net
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了首页> C#> DataTables标题显示为一行? MVC Asp.net,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2771字,纯文字阅读大概需要4分钟。
内容图文
![首页> C#> DataTables标题显示为一行? MVC Asp.net](/upload/InfoBanner/zyjiaocheng/666/428264089bea4ffbb36be81b7aa038bc.jpg)
我正在跟一个粗略的课程一起学习,我正处于要使用数据表呈现表的阶段,但是由于某种原因,当它呈现我的表时,会将TH作为td推入表中了吗?
屏幕截图
<table id="your_contacts" class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.firstName)</th>
<th>@Html.DisplayNameFor(model => model.lastName)</th>
<th>@Html.DisplayNameFor(model => model.email)</th>
<th>@Html.DisplayNameFor(model => model.phonePrimary)</th>
<th>@Html.DisplayNameFor(model => model.phoneSecondary)</th>
<th>@Html.DisplayNameFor(model => model.birthday)</th>
<th>@Html.DisplayNameFor(model => model.address1)</th>
<th>@Html.DisplayNameFor(model => model.address2)</th>
<th>@Html.DisplayNameFor(model => model.city)</th>
<th>@Html.DisplayNameFor(model => model.postcode)</th>
<th>Details</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.firstName)</td>
<td>@Html.DisplayFor(modelItem => item.lastName)</td>
<td>@Html.DisplayFor(modelItem => item.email)</td>
<td>@Html.DisplayFor(modelItem => item.phonePrimary)</td>
<td>@Html.DisplayFor(modelItem => item.phoneSecondary)</td>
<td>@Html.DisplayFor(modelItem => item.birthday)</td>
<td>@Html.DisplayFor(modelItem => item.address1)</td>
<td>@Html.DisplayFor(modelItem => item.address2)</td>
<td>@Html.DisplayFor(modelItem => item.city)</td>
<td>@Html.DisplayFor(modelItem => item.postcode)</td>
<td>@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
<td>@Html.HiddenFor(modelItem => item.UserId)</td>
</tr>
}
</table>
<!-- Used to call scripts after the Jquery/JS has loaded.-->
@section Scripts
{
<script type="text/javascript">
$(function () {
$("#your_contacts").dataTable({
"pagingType": "full_numbers"
, "scrollY": "600px"
, "columnDefs": [
{ "width": "40px", "targets": 0 }
, { "width": "40px", "targets": 1 }
, { "width": "40px", "targets": 2 }
, { "width": "45px", "targets": 3 }
, { "width": "45px", "targets": 4 }
, { "width": "45px", "targets": 5 }
, { "width": "45px", "targets": 6 }
, { "width": "45px", "targets": 7 }
, { "width": "45px", "targets": 8 }
, { "width": "45px", "targets": 9 }
, { "width": "45px", "targets": 10 }
, { "width": "45px", "targets": 11 }
]
, "order": [[1, "asc"]]
, "dom": 'Rlfrtip'
, "stateSave": "true"
, "lengthMenu": [[-1, 10, 20, 50, 100], ["All", 10, 20, 50, 100]]
});
});
</script>
}
我是同时使用.net和datatables的人,谁能发现为什么会这样做呢?它甚至与排列按钮不对齐.
解决方法:
将您的“标题”换成< thead>其余< tbody>中的行元件.该插件按第一列(由“ order”定义的[[1,“ asc”]])对所有行进行排序,以使结果为Deforest->.名字->詹姆士
<table id="your_contacts" class="table">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.firstName)</th>
....
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
....
}
</tbody>
</table>
内容总结
以上是互联网集市为您收集整理的首页> C#> DataTables标题显示为一行? MVC Asp.net全部内容,希望文章能够帮你解决首页> C#> DataTables标题显示为一行? MVC Asp.net所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。