我正在尝试学习 ASP.NET MVC 4,所以我正在尝试制作一个博客来帮助我学习。我似乎无法设置发布时的日期时间,它只是使用当前时间。
这是我的博客模型的代码
public class BlogPost
{
public int ID { get; set; }
public string Title { get; set; }
[DataType(DataType.MultilineText)]
public string Content { get; set; }
public DateTime DateTimePosted { get; set; }
public string Author { get; set; }
public List<Comment> Comments { get; set; }
public BlogPost()
{ }
public BlogPost(int id, string title, string content, string author)
{
this.ID = id;
this.Title = title;
this.Content = content;
this.DateTimePosted = DateTime.Now;
this.Author = author;
}
}
public class BlogPostDBContext : DbContext
{
public BlogPostDBContext()
: base("DefaultConnection")
{ }
public DbSet<BlogPost> BlogPosts { get; set; }
}
如何更改它以存储发布日期时间?