Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 没有';不显示数据库中的数据_C#_Asp.net_Asp.net Mvc_Entity Framework - Fatal编程技术网

C# 没有';不显示数据库中的数据

C# 没有';不显示数据库中的数据,c#,asp.net,asp.net-mvc,entity-framework,C#,Asp.net,Asp.net Mvc,Entity Framework,我想显示数据库中的所有数据 但它不起作用。 我的Web.config文件 <connectionStrings> <add name="EFDbContext" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=NewsList;Integrated Security=True"/> 模型 看法 @model

我想显示数据库中的所有数据

但它不起作用。 我的Web.config文件

 <connectionStrings>
<add name="EFDbContext" providerName="System.Data.SqlClient"
     connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=NewsList;Integrated Security=True"/>
模型

看法

@model IEnumerable
@{
ViewBag.Title=“新闻”;
}
@foreach(模型中的var p)
{
@p、 头衔
@p、 描述
@p、 正文
} 
现在我没有任何例外。仅在浏览页面时清除。

例如:

public class NewsRepository  : INewsRepository 
{
    private YourDbContext db = null;

    public List<NewsList> NewsList
    {
        return this.db.NewsList.ToList();
    }

    public NewsRepository()
    {
        this.db = new NewsRepository();
    }
}

public class YourDbContext : DbContext
{
    public DbSet<NewsList> NewsList {get; set;}
}
公共类新闻存储库:INewsRepository
{
private YourDbContext db=null;
公共列表新闻列表
{
返回此.db.NewsList.ToList();
}
公共新闻存储库()
{
this.db=新新闻存储库();
}
}
公共类YourDbContext:DbContext
{
公共数据库集新闻列表{get;set;}
}

请添加
新闻存储库
的代码(或在WSRepository中实现的任何代码)。数据库里有数据吗?此外,您还可以在返回视图(repository.NewsList)的
中设置断点
查看
NewsList
是否返回任何数据。如果调用
视图(repositor.NewsList.ToList()),功能会有任何变化?在这里你们可以看到所有的连接。数据库中的数据埃里克·飞利浦,不,并没有任何变化。模型中的所有数据类型都是错误的。非常感谢。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewsList.Domain.Entities
{
public class News
{
    public int NewsID { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string Text { get; set; }
}
}
@model IEnumerable<NewsList.Domain.Entities.News>

@{
   ViewBag.Title = "News";
 }

@foreach (var p in Model)
{
<div class="item">
    <h3>@p.Title</h3>
    @p.Description
    <h4>@p.Text</h4>
</div>
} 
public class NewsRepository  : INewsRepository 
{
    private YourDbContext db = null;

    public List<NewsList> NewsList
    {
        return this.db.NewsList.ToList();
    }

    public NewsRepository()
    {
        this.db = new NewsRepository();
    }
}

public class YourDbContext : DbContext
{
    public DbSet<NewsList> NewsList {get; set;}
}