public async Task <IActionResult> Comment([Bind("ID, ArticleID, CreateTime, NickName, Content")] Comment comment) { if (ModelState.IsValid) { comment.CreateTime = DateTime.Now; _context.Add(comment); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(ReadArticle), new { id = comment.ArticleID })); }
public async Task <IActionResult> Create([Bind("ID,Title,CreateTime,LastModifyTime,MarkdownContent,HTMLContent")] Article article) { if (ModelState.IsValid) { // 设置时间 DateTime now = DateTime.Now; article.CreateTime = now; article.LastModifyTime = now; // 生成 HTML BuildArticle(article); _context.Add(article); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(article)); }