当用户在我的网站上创建一个帐户时,他们会有一个像这个domain.com/{username}的网址,然后它会显示该用户的所有帖子。该博客将显示一小部分用户的信息。这是我的模特:
[Table("Post")]
public class Post
{
private DateTime _date = DateTime.Now;
[Key]
public int postID { get; set; }
[Required]
public string title { get; set; }
[Required]
public string username { get; set; }
[Required]
public string slugPost { get; set; }
[AllowHtml]
[Required]
public string content { get; set; }
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime publicdate
{
get { return _date; }
set { _date = value; }
}
}
这是我的路由器:
routes.MapRoute(
name: "Profile",
url: "blog/{username}/",
defaults: new { controller = "Blog", action = "index", username = UrlParameter.Optional }
);
这是我的控制者:
private SystemContext db = new SystemContext();
private UsersContext udb = new UsersContext();
public ActionResult Index(string username)
{
var model = new ProfileContent();
model.Profile = (from u in udb.UserProfiles
where u.UserName == username
select u).FirstOrDefault();
model.Baidangs = (from p in db.Posts
where p.username == username
select p).ToList();
return View(model);
}
我总是收到错误
支持'UserContext'上下文的模型已更改
虽然这是我第一次构建它,但即使我已将其删除。
我收到错误“无效的对象名称'dbo.Posts'。”
我怎样才能解决这些问题?