ASP.. NET MVC视图没有显示来自数据库的正确信息

本文关键字:数据库 信息 显示 MVC NET 视图 ASP | 更新日期: 2023-09-27 18:07:57

所以我正在构建一个要在我们的网站上显示的报告,我为查询创建了一个视图并将其放入我们的. 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>

ASP.. NET MVC视图没有显示来自数据库的正确信息

像这样将view转换为OrderBy之前的List。view.ToList().OrderBy() .

IEnumerable<qryCalibrationEquipmentTracker> view = db.qryCalibrationEquipmentTrackers;
view = view.ToList().OrderBy(a => a.NextCalibrationDate);
return View(view);

这是微软的问题,因为这是一个查询,所以没有主键。微软介入并随机选择了一个主键。