无法填充视图或视图模型已更新 [英] Unable To populate view or view model Updaed

查看:76
本文介绍了无法填充视图或视图模型已更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在跟进此问题

Hi I am following up on this question here 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

不幸的是,当我运行项目时,我得到了这个回报 这感觉像是从SQL数据库(SQL Server 2008R2)检索数据失败.但是我没有收到任何错误消息,尽管我会的,但我知道数据视图在那里,正如我在SQL Management Studio和Visual Studio 2017的服务器资源管理器中检查过的那样. 我猜测虽然这也可能是将我的数据传输对象映射到我的敲除视图模型或将数据绑定到我的视图的错误.

Unfortunately, when I run the project I get this return This feels like a failure to retrieve the data from the SQL Database (SQL Server 2008R2). However I am getting no error message, which I though I would, I know the data view is there as I have checked in SQL Management studio and in Server Explorer of Visual Studio 2017. I am guessing though it could also be an error mapping my Data transfer Objects to my Knockout View Model or my Data bindings to my View.

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

When I try to look in Visual Studio 2017 I can not find(?) any problems, build errors nor the values of the objects (In the past I have been able to see the local values of objects in vs 2012 build WPF apps).

我可以和某人告诉我最佳的调试步骤,以及我应该在Visual Studio 2017中寻找开始跟踪这些错误的地方,我以为是本地"选项卡,但是它是空的,请参见屏幕截图

I could do with someone telling me the best debug steps and where I should be looking in visual studio 2017 to start tracking down these errors, I thought it was the Local tab but this is empty, see screen shot

总结 1.捕获此错误的最佳方法是什么 2.我可以找出运行时加载到我的模型和视图模态中的内容吗? 3如果数字2的答案是肯定的,那我应该去哪里找?

In summary 1. What is the best way to trap this error 2. Can I find out what has been loaded into my Model and View Modal during run time? 3 If the answer to number 2 is yes, where should I be looking?

这是我的查看代码

   @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; }
    }
}

非常感谢

推荐答案

帮助他人.

问题出在我正在按照数据库优先方法进行调整,而我没有正确创建模型文件

The problem was as I was adapting the work through to Database first approach and I had not correctly created my model file

为帮助调试正在运行的Web应用程序,我向Get API发布了一个请求

To help with debug on the running web app I posted a request to my Get API

api/RequistionsForApprovals

这返回了空的回报,证明问题出在我的数据读取而不是我的敲除模型和绑定.阅读更多内容后,我认为我没有正确定义SQL视图EF模型的主键,因此,如

This returned a blank return, proving the problem was with my data reading not my knock out models and bindings. After reading up a bit more I thought I had not defined correctly the primary key of the EF model of my SQL view, therefore I needed to edit the edmx file as in the case here.

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

However I could not find my edmx file in my solution. Therefore I went through the process of adding a new item, Data, then choosing ADO.net Entity Data model. This created the mappings to my model class and a context which I was able to use with my controller

一个简单的错误,但是在学习新流程时通常就是这种情况!

A bit of a simple mistake, but that is often the case when learning a new process!

希望它对其他人有帮助

这篇关于无法填充视图或视图模型已更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆