无法填充视图或视图模型更新

Unable To populate view or view model Updaed

您好,我正在跟进这个问题 and working through a proof of concept for a SPA using our Company database data from a series of examples / articles Using Web API 2 with Entity Framework 6

不幸的是,当我 运行 这个项目时,我得到了这个 return 这感觉就像无法从 SQL 数据库(SQL Server 2008R2)检索数据。但是我没有收到任何错误消息,虽然我会收到,但我知道数据视图在那里,因为我已经在 SQL Management studio 和 Visual Studio 2017 的服务器资源管理器中进行了检查。 我猜这也可能是将我的数据传输对象映射到我的 Knockout 视图模型或我的数据绑定到我的视图的错误。

当我尝试查看 Visual Studio 2017 时,我找不到(?)任何问题、构建错误或对象的值(过去我已经能够看到对象的本地值在 vs 2012 中构建 WPF 应用程序)。

有人告诉我最好的调试步骤以及我应该在 visual studio 2017 年开始追踪这些错误的位置,我认为它是“本地”选项卡,但它是空的,请参阅屏幕射击

综上所述 1. 捕获此错误的最佳方法是什么 2. 我可以找出在 运行 时间内加载到我的模型和视图模态中的内容吗? 3 如果问题 2 的答案是肯定的,我应该去哪里找?

这是我的查看代码

   @section scripts {
    @Scripts.Render("~/bundles/app")
}

<div class="page-header">
    <h1>Requistions Approval</h1>
</div>

<div class="row">

    <div class="col-md-4">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2 class="panel-title">Requistions</h2>
            </div>
            <div class="panel-body">
                <ul class="list-unstyled" data-bind="foreach: Requistions">
                    <li>
                        <strong><span data-bind="text: Requistion"></span></strong>
                        : <span data-bind="text: Line"></span>
                        : <span data-bind="text: ReqnValue"></span>
                        : <span data-bind="text: OrigName"></span>
                        : <span data-bind="text: LineReqnRaised"></span>
                        : <span data-bind="text: ReasonForReqn"></span>
                        : <span data-bind="text: GLDescription"></span>
                        <small><a href="#">Details</a></small>
                    </li>
                </ul>
            </div>
        </div>
        <div class="alert alert-danger" data-bind="visible: error"><p data-bind="text: error"></p></div>
    </div>

  </div>

这是我的控制器代码

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;
using Requestions_Api_POC.Models;

namespace Requestions_Api_POC.Controllers
{
    public class RequistionsForApprovalsController : ApiController
    {
        private Requestions_Api_POCContext db = new Requestions_Api_POCContext();

        // GET api/RequistionsForApprovals
        public IQueryable<RequistionHeaderDTO> GetRequistionsForApprovals()
        {
            var Requistions = from b in db.RequistionsForApprovals
                              select new RequistionHeaderDTO()
                              {
                                  ID = b.ID,
                                  Requisition = b.Requisition,
                                  ReqnValue = b.ReqnValue,
                                  ApprovedValue = b.ApprovedValue,
                                  OrigName = b.OrigName,
                                  Line = b.Line,
                                  LineReqnRaised = b.LineReqnRaised,
                                  DueDate = b.DueDate,
                                  ReasonForReqn = b.ReasonForReqn,
                                  Supplier = b.Supplier,
                                  GLDesc = b.GLDesc,
                                  CurrentHolder = b.CurrentHolder,
                                  CurName = b.CurName,
                                  CurEmail = b.CurName,
                                  HoldersRouteNum = b.HoldersRouteNum,
                                  DateActioned = b.DateActioned,
                                  DatabaseName = b.DatabaseName,
                                  AdUser = b.AdUser,
                                  ServerName = b.ServerName
                              };
            return Requistions;


        }

这是我的数据传输对象

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Requestions_Api_POC.Models
{
    public class RequistionHeaderDTO
    {
        public string ID { get; set; }
        public string Requisition { get; set; }
        public decimal? ReqnValue { get; set; }
        public decimal? ApprovedValue { get; set; }
        public string OrigName { get; set; }
        public decimal Line { get; set; }

        public System.DateTime? LineReqnRaised { get; set; }
        public DateTime? DueDate { get; set; }
        public string ReasonForReqn { get; set; }
        public string Supplier { get; set; }
        public string GLDesc { get; set; }
        public string CurrentHolder { get; set; }
        public string CurName { get; set; }
        public string CurEmail { get; set; }
        public decimal? HoldersRouteNum { get; set; }
        public DateTime? DateActioned { get; set; }
        public string DatabaseName { get; set; }
        public string AdUser { get; set; }
        public string ServerName { get; set; }
    }
}

非常感谢

帮助别人。

问题出在我将工作调整为数据库优先方法时,我没有正确创建模型文件

为了帮助调试 运行 网络应用程序,我向我的 Get API

发布了一个请求
api/RequistionsForApprovals

这 return 一片空白 return,证明问题出在我的数据读取上,而不是我的淘汰模型和绑定。阅读更多内容后,我认为我没有正确定义 SQL 视图的 EF 模型的主键,因此我需要编辑 edmx 文件,就像 here 的情况一样。

但是我在我的解决方案中找不到我的 edmx 文件。因此,我经历了添加新项目数据的过程,然后选择 ADO.net 实体数据模型。这创建了到我的模型 class 的映射以及我能够与我的控制器一起使用的上下文

有点简单的错误,但在学习新过程时经常会出现这种情况!

希望对其他人有所帮助