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; }
}
投稿された日時を保存するようにこれを変更するにはどうすればよいですか?