我有一个博客文章的视图,它返回包含帖子和评论的视图模型,以及评论表单所在页面末尾的锚点。
在我提交评论表单后,我希望POST方法返回View(),但链接中有锚点
ie: www.blog.com/article/my-first-article#comments
现在我只有 www.blog.com/article/my-first-article ,为了查看验证错误,您必须向下滚动到评论。
任何想法?
谢谢, 亚历
[HttpPost] public ActionResult Index(ArticleWithCommentsViewModel vm) { if (ModelState.IsValid) { var newComm = new comment(); newComm.Name = vm.Name; newComm.Email = vm.Email; newComm.CreatedDate = DateTime.Now; newComm.Comm = vm.Comment; newComm.ArticleID = vm.ArticleToComment; _db.comments.InsertOnSubmit(newComm); _db.SubmitChanges(); return RedirectToAction("Index", "Article"); } ArticleWithCommentsViewModel vm2 = new ArticleWithCommentsViewModel(); vm2.TheArticle = _db.Articles.ToList().Single(x => x.ArticleID == vm.ArticleToComment); vm2.comments = _db.comments.ToList().Where(x => x.ArticleID == vm.ArticleToComment); return View(vm2); }
答案 0 :(得分:1)
思考可能有点低技术但它可能有效:
return Redirect("www.blog.com/article/my-first-article#comments");