使用Blazor从API检索数据。数据未被提取

使用Blazor从API检索数据。数据未被提取,api,asp.net-core,crud,blazor,Api,Asp.net Core,Crud,Blazor,使用ASP.NETCore3.0和Blazor。我正在修改此处找到的项目: 我使用scofolddbcontext来构建上下文文件和模型类。VS与数据库联系以创建所需文件没有问题 Razor视图: @using ShopLive1.Shared.Models @page "/fetchemployees" @inject HttpClient Http <h1>Shop Live - Repair Order Update</h1> @if(roList == nu

使用ASP.NETCore3.0和Blazor。我正在修改此处找到的项目:

我使用scofolddbcontext来构建上下文文件和模型类。VS与数据库联系以创建所需文件没有问题

Razor视图:

@using ShopLive1.Shared.Models
@page "/fetchemployees"
@inject  HttpClient Http

<h1>Shop Live - Repair Order Update</h1>

@if(roList == null)
{
    <p><em>Loading....</em></p>
}
else
{
    <table class="table">
        <thead>
            <tr>
                <th>Control Number</th>
                <th>VIN</th>
                <th>Make</th>
                <th>Model</th>
                <th>Customer</th>
                <th>Repair Stage</th>
                <th>Location</th>
                <th>Assigned</th>
            </tr>
        </thead>
        <tbody>
            @foreach(var ro in roList)
            {
                <tr>
                    <td>@ro.ControlNumber</td>
                    <td>@ro.Vin</td>
                    <td>@ro.Make</td>
                    <td>@ro.Model</td>
                    <td>@ro.Customer</td>
                    <td>@ro.Stage</td>
                    <td>@ro.VehicleLocation</td>
                    <td>@ro.Technician</td>
                </tr>
            }
        </tbody>
    </table>
}


@functions{
    RepairOrder[] roList;

    protected override async Task OnInitAsync()
    {
        roList = await Http.GetJsonAsync<RepairOrder[]>("api/RepairOrder/Index");
    }
}
@使用ShopLive1.Shared.Models
@第页“/fetchemployees”
@注入HttpClient Http
车间实时-维修订单更新
@if(roList==null)
{
加载

} 其他的 { 控制号码 VIN 制作 模型 顾客 修复阶段 地方 分配 @foreach(roList中的var ro) { @控制号 @罗文 @ro.制造 @反渗透模型 @ro.客户 @舞台 @反渗透车辆定位 @反渗透技术员 } } @功能{ 维修订单[]劳力士; 受保护的重写异步任务OnInitAsync() { roList=wait Http.GetJsonAsync(“api/RepairOrder/Index”); } }
数据访问层类别:

ShopLiveContext db = new ShopLiveContext();

        //To get all repair orders
        public List<RepairOrder> GetAllRepairOrders()
        {
            try
            {
                return db.RepairOrder.ToList();
            }
            catch
            {
                throw;
            }

        }

        //To add new Repair Orders
        public void AddRepairOrder(RepairOrder ro)
        {
            try
            {
                db.RepairOrder.Add(ro);
                db.SaveChanges();
            }
            catch
            {
                throw;
            }
        }

        //To update Repair Orders
        public void UpdateRepairOrder(RepairOrder ro)
        {
            try
            {
                db.Entry(ro).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch
            {
                throw;
            }
        }

        //Get the details of a particular RO
        public RepairOrder GetRepairOrderDetails(int id)
        {
            try
            {
                RepairOrder ro = db.RepairOrder.Find(id);
                return ro;
            }
            catch
            {
                throw;
            }
        }

        //To delete a record
        public void DeleteRepairOrder(int id)
        {
            try
            {
                RepairOrder ro = db.RepairOrder.Find(id);
                db.RepairOrder.Remove(ro);
                db.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
    }
}
ShopLiveContext db=new ShopLiveContext();
//获取所有维修订单
公共列表GetAllRepairOrders()
{
尝试
{
返回db.RepairOrder.ToList();
}
接住
{
投
}
}
//添加新维修单的步骤
公共无效添加维修订单(维修订单ro)
{
尝试
{
db.RepairOrder.Add(ro);
db.SaveChanges();
}
接住
{
投
}
}
//更新维修单的步骤
公共无效更新修复程序(修复订单ro)
{
尝试
{
db.Entry(ro.State=EntityState.Modified;
db.SaveChanges();
}
接住
{
投
}
}
//获取特定RO的详细信息
public RepairOrder GetRepairOrderDetails(int id)
{
尝试
{
RepairOrder ro=db.RepairOrder.Find(id);
返回ro;
}
接住
{
投
}
}
//删除记录
公共订单(内部id)
{
尝试
{
RepairOrder ro=db.RepairOrder.Find(id);
db.修理单.拆卸(ro);
db.SaveChanges();
}
接住
{
投
}
}
}
}
数据上下文文件:

public ShopLiveContext()
        {
        }

        public ShopLiveContext(DbContextOptions<ShopLiveContext> options)
            : base(options)
        {
        }

        public virtual DbSet<RepairOrder> RepairOrder { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Data Source=sumcso-8g5lr52;Initial Catalog=ShopLive;Integrated Security=True");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("ProductVersion", "3.0.0-preview5.19227.1");

            modelBuilder.Entity<RepairOrder>(entity =>
            {
                entity.Property(e => e.ControlNumber)
                    .IsRequired()
                    .HasMaxLength(13)
                    .IsUnicode(false);

                entity.Property(e => e.Customer)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Make)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.ManagerNote)
                    .HasMaxLength(5000)
                    .IsUnicode(false);

                entity.Property(e => e.Model)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Stage)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.TechncicianNote)
                    .HasMaxLength(5000)
                    .IsUnicode(false);

                entity.Property(e => e.Technician)
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.VehicleLocation)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);

                entity.Property(e => e.Vin)
                    .HasColumnName("VIN")
                    .HasMaxLength(20)
                    .IsUnicode(false);
            });
        }
    }
publicshopplivecontext()
{
}
public ShopLiveContext(DbContextOptions)
:基本(选项)
{
}
公共虚拟数据库集修复顺序{get;set;}
配置时受保护的覆盖无效(DBContextOptions Builder Options Builder)
{
如果(!optionBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(“数据源=sumcso-8g5lr52;初始目录=ShopLive;集成安全性=True”);
}
}
模型创建时受保护的覆盖无效(ModelBuilder ModelBuilder)
{
modelBuilder.HasAnnotation(“ProductVersion”,“3.0.0-preview5.19227.1”);
modelBuilder.Entity(Entity=>
{
属性(e=>e.ControlNumber)
.IsRequired()
.HasMaxLength(13)
.IsUnicode(假);
entity.Property(e=>e.Customer)
.IsRequired()
.HasMaxLength(50)
.IsUnicode(假);
entity.Property(e=>e.Make)
.HasMaxLength(50)
.IsUnicode(假);
entity.Property(e=>e.ManagerNote)
.HasMaxLength(5000)
.IsUnicode(假);
Property(e=>e.Model)
.HasMaxLength(50)
.IsUnicode(假);
Property(e=>e.Stage)
.IsRequired()
.HasMaxLength(50)
.IsUnicode(假);
entity.Property(e=>e.TechncicianNote)
.HasMaxLength(5000)
.IsUnicode(假);
entity.Property(e=>e.Technician)
.HasMaxLength(50)
.IsUnicode(假);
entity.Property(e=>e.VehicleLocation)
.IsRequired()
.HasMaxLength(50)
.IsUnicode(假);
实体属性(e=>e.Vin)
.HasColumnName(“VIN”)
.HasMaxLength(20)
.IsUnicode(假);
});
}
}
当我运行项目并单击指向新页面的链接时,它会显示“正在加载…”,但不会从数据库中获取数据并加载表


有人能给我指出正确的方向,我可能会错过什么吗

我想这是因为你的url错了。你用

“api/RepairOrder/Index”而不是“api/Employee/Index”

这个应用程序可能还有其他问题,但这是我第一次注意到弱视

注:

  • 这个应用程序很古老。几乎是史前的。它甚至在我听说布拉佐之前就已经写好了

  • 您应该使用postman或Fiddler等工具来验证Web API是否返回数据。这可以帮你省去很多麻烦

  • 我建议你不要跟着这个家伙写的文章和书来学习Blazor。