这是问题unable-to-populate-view-or-view-model的后续内容 使用来自一系列示例/文章Using Web API 2 with Entity Framework 6的我们公司的数据库数据,对SPA进行概念验证。这是我第一次尝试SPA
不幸的是,当我运行项目时,我得到了,这显然是错误的,我已经检查了SQL端,并且SQL视图中有数据
我看不到我的错误是什么。任何人都可以发现它吗?
如果我正确理解了文章,那么我已经设置了视图,然后调用Get API来填充Json视图模型的视图模型。然后,这将基于EF6调用我的服务器模型。
但是,没有来自SQL Server的错误消息,也没有构建错误,所以我的猜测是,当我在网络上进行测试时,并没有收到错误消息,感觉就像我在不要求建立连接正确地建立数据库,否则当我不在网络中时,代码将不会找到数据库连接,因为SQL Server将不在那儿并返回这种错误?
我可以根据要求发布更多代码。
这是我的查看代码
@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; }
}
}