问题描述
请帮帮我。 我是新的 .net core mvc 和这里。 我正在开发一个非常简单的博客网站。但我收到一个错误。 课后
using System.Collections.Generic;
namespace DataAccess
{
public class Post
{
public int PostId { get; set; }
public string PostTitle { get; set; }
public string PostWriter { get; set; }
public string PostDate { get; set; }
public string PostİmageUrl { get; set; }
public string PostContent { get; set; }
public List<Post> Posts { get; set; }
}
}
using System.Collections.Generic;
using System.Linq;
using DataAccess.Abstract;
using Microsoft.EntityFrameworkCore;
using static DataAccess.Entity;
namespace DataAccess.Concrete.sqlite
{
public class PostRepository : IPostRepository
{
private Context db = new Context ();
public List<Post> GetAll()
{
return db.Posts.ToList();
}
public Post GetById(int id)
{
return db.Posts.Find(id);
}
}
}
家庭控制器
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Blog.Models;
using DataAccess.Abstract;
using DataAccess;
namespace Blog.Controllers
{
public class HomeController : Controller
{
private IPostRepository _postRepository;
private ICommentRepository _commentRepository;
private ICategoryRepository _categoryRepository;
public HomeController(IPostRepository postRepository,ICommentRepository commentRepository,ICategoryRepository categoryRepository)
{
this._postRepository = postRepository;
this._commentRepository = commentRepository;
this._categoryRepository = categoryRepository;
}
public IActionResult Index()
{
var Post = new Post ()
{
Posts = _postRepository.GetAll()
};
return View(Post);
// return View(new Postviewmodel()
// {
// Posts = _postRepository.GetAll()
// });
}
public IActionResult Privacy()
{
return View();
}
}
}
我的观点
@model Post
@{
var P = Model.Posts;
}
<!-- Post Content Column -->
<div class="col-lg-8">
<!-- Title -->
@foreach (var item in P)
{
<h1 class="mt-4">@item.PostTitle</h1>
}
</div>
这是我的代码。 [我的数据库][1] [我的错误][2] [1]:https://i.stack.imgur.com/IOc10.png [2]:https://i.stack.imgur.com/5ADC2.png 你觉得我能怎么解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)