【发布时间】:2015-08-13 12:17:39
【问题描述】:
所以我正在构建要在我们的网站上显示的报告,我为 qry 创建了一个视图并将其放入我们的 .EDMX 文件中。我可以使用该查询为站点设置视图,但是数据库中的数据与屏幕上显示的数据不匹配。日期搞砸了,其他一切都匹配。有什么想法吗?
SELECT TOP 1000 [Name]
,[Manufacturer]
,[SerialNumber]
,[TSIFBarcode]
,[NextCalibrationDate]
,[Description]
,[CalibrationCost]
,[Location]
,[RoutineInspection]
,[Comment]
,[Priority]
FROM [InsertDBHere]
这是我的 sql 代码,下面是我从控制器创建视图的代码:
IEnumerable<qryCalibrationEquipmentTracker> view = db.qryCalibrationEquipmentTrackers;
view = view.OrderBy(a => a.NextCalibrationDate);
return View(view);
下面是视图代码
@model IEnumerable<MvcDBFirst.Models.qryCalibrationEquipmentTracker>
@{
ViewBag.Title = "Calibration Tracking Report";
}
<h2>Calibration Tracking Report</h2>
@if (ViewBag.PrintMode == null || !ViewBag.PrintMode)
{
<div class="float-right clear-fix">
<div class="amMenu">
<ul class="amMenuLinksHoriz clear-fix">
<li>
<a href="@Url.Action("ExportCalTracking", "Reports")">
<img src="@Url.Content("~/images/assetmgr/printer.png")" height="25px" alt="Printer" />
</a>
</li>
<li>
@*<a href="@Url.Action("ExcelCalTracking", "Reports")">*@
<a onclick="postTableData('amCalIndexTable')">
<img src="@Url.Content("~/images/assetmgr/excel.png")" height="25px" alt="Excel" />
</a>
</li>
</ul>
</div>
</div>
}
<h2>Report Run on @DateTime.Now.ToString()</h2>
<table class="amCalIndexTable">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Manufacturer)
</th>
<th>
@Html.DisplayNameFor(model => model.SerialNumber)
</th>
<th>
@Html.DisplayNameFor(model => model.TSIFBarcode)
</th>
<th>
@Html.DisplayNameFor(model => model.NextCalibrationDate)
</th>
<th>
@Html.DisplayNameFor(model => model.Priority)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.CalibrationCost)
</th>
<th>
@Html.DisplayNameFor(model => model.Location)
</th>
<th>
@Html.DisplayNameFor(model => model.RoutineInspection)
</th>
<th>
@Html.DisplayNameFor(model => model.Comment)
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Manufacturer)
</td>
<td>
@Html.DisplayFor(modelItem => item.SerialNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.TSIFBarcode)
</td>
<td>
@Html.DisplayFor(modelItem => item.NextCalibrationDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Priority)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
@*Html.ActionLink(item.Description, "Details", "tblItems",
new
{
type = item.fkItemType,
serialNumber = item.SerialNumber,
owner = item.fkOwner
}, null
)*@
</td>
<td>
@Html.DisplayFor(modelItem => item.CalibrationCost)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location)
</td>
<td>
@Html.DisplayFor(modelItem => item.RoutineInspection)
</td>
<td>
@Html.DisplayFor(modelItem => item.Comment)
</td>
</tr>
}
</tbody>
【问题讨论】:
-
日期如何“搞砸”?我们无法从这里看到您的屏幕,您需要指定问题所在。显示的代码没有任何问题。
-
所以这是来自数据库
2013-05-14 00:00:00 2013-10-07 00:00:00 2014-11-11 00:00:00 NULL 2015-11-05 00:00:00的一些日期,这些日期是正确的,但在视图中它们只会出现在所有 5 个2015-10-07中 -
显示 MVC 视图的代码
-
@Neal:发布的代码中没有任何内容会导致这种情况。
-
我已添加查看代码
标签: c# sql asp.net asp.net-mvc