【发布时间】:2015-03-03 12:28:37
【问题描述】:
我想我会分享这个小问题。对于这个特定的问题,我从高处和低处看,找不到答案。
我做错了什么:在 foreach 中遍历集合时,请确保将“tbody”标签放置在 foreach 语句的外部!
这就是我所拥有的
- WaitTimesData.cshtml:
@model IEnumerable
<SharePointWaitTimesWebMVC5.Models.FeedData>
@{ ViewBag.Title = "WaitTimesData"; }
<h2>Wait Times Data</h2>
@using (Html.BeginForm()) {
<table class="table table-bordered table-hover table-responsive">
<thead>
<tr>
<th style="text-align:center; padding:5px;">
Id
</th>
<th style="text-align:center; padding:5px;">
@Html.DisplayNameFor(model => model.Title)
</th>
<th style="text-align:center; padding:5px;">
Park
</th>
<th style="text-align:center; padding:5px;">
Status
</th>
<th style="text-align:center; padding:5px;">
Opens
</th>
<th style="text-align:center; padding:5px;">
Wait
</th>
<th style="text-align:center; padding:5px;">
@Html.DisplayNameFor(model => model.Modified)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td style="text-align:center; padding:5px;">
@Html.DisplayFor(modelItem => item.Id)
</td>
<td style="padding:5px;">
@Html.DisplayFor(modelItem => item.Title)
</td>
<td style="padding:5px;">
@Html.DisplayFor(modelItem => item.WTB_UO_Park)
</td>
<td style="padding:5px;">
@Html.DisplayFor(modelItem => item.WTB_Content_Status)
</td>
<td style="padding:5px;">
@Html.DisplayFor(modelItem => item.WTB_Opens_At)
</td>
<td style="text-align:center;">
@Html.DisplayFor(modelItem => item.WTB_Wait_Time)
</td>
<td style="padding:5px;">
@DateTime.Parse(item.Modified).ToLocalTime()
</td>
</tr>
}
</tbody>
</table>
}
- _Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - SharePoint Wait Times Feed</title>
@Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("SharePoint Wait Times Feed", "Index", "Home", null, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("View Feed Data", "WaitTimesData", "Home")</li>
<li>@Html.ActionLink("JSON Data", "WaitTimesJsonData", "Home")</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - Share Point Wait Times Feed</p>
</footer>
</div>
@RenderSection("scripts", required: false) @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jquerytable") @Scripts.Render("~/bundles/bootstrap")
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$('.table').tablesorter();
});
});
</script>
</body>
</html>
- BundleConfig.cs:
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new ScriptBundle("~/bundles/jquerytable").Include(
"~/Scripts/jquery.tablesorter.js"
));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/bootstrap-responsive.css"));
}
}
【问题讨论】:
-
社区感谢人们分享遇到的错误的详细信息,但为了最大限度地为未来的访问者提供帮助,请稍微改变一下格式。与其将“已解决”放在标题中,不如将您的问题和解决方案分开。表达你的问题和标题,就好像你根本不知道答案一样;然后在答案部分回答它。一个比“不排序,不工作,什么都不做”更具描述性的标题将帮助其他人更容易找到它。
-
Stack Overflow 鼓励人们在可能的情况下回答自己的问题,但问题和答案绝对应该分开,并且将自己的答案标记为“已接受”比使用“已解决”更可取,就像其他论坛一样。感谢您抽出宝贵时间分享此内容!
-
这对我帮助很大!谢谢分享!
标签: jquery twitter-bootstrap-3 asp.net-mvc-5 tablesorter