localhost 目前无法处理这个请求。在 ASP.NET 控制器中用于从 dbContext 中检索数据

问题描述 投票:0回答:0

我正在使用

dbContext
实例来检索 asp.net 视图中的所有数据,但最终出现此错误

此页面无法正常工作 - 本地主机当前无法处理此请求。 HTTP 错误 500.

我在数据库中有一条记录,但无法检索它。

这是我检索所有数据的方法

private readonly DataContext db;

public PatientsData(DataContext _db) {
    db = _db;
}

public IEnumerable<Patients> GetAllPatients() 
{
    var patients = db.Patients.ToList();
    return patients;
}

这是我的

dbContext

public class DataContext : DbContext
{
    //private readonly IConfiguration Configuration;

    public DataContext(DbContextOptions<DataContext> options)
        : base(options)
    {
    }
       
    public DbSet<Patients> Patients { get; set; }
} 

这是我的看法

@model V._3._0.Models.PatientsData
<table>
    @foreach(var patients in Model.GetAllPatients())
    {
        <tr>
            <td>@patients.Id.</td>
            <td>@patients.Name</td>
            <td>@patients.Status</td>
            <td>@patients.DateOfAdm</td>
            <td>@patients.DateOfDis</td>
            
        </tr>
    }
</table> 

我无法发现我哪里出错了......

c# asp.net database asp.net-core-mvc dbcontext
© www.soinside.com 2019 - 2024. All rights reserved.