【发布时间】:2012-06-10 21:11:41
【问题描述】:
我有一个博客帖子的视图,它返回一个包含帖子和 cmets 的视图模型,以及评论表单所在页面末尾的锚点。
在我提交评论表单后,我希望 POST 方法返回 View() 但在链接中带有锚点
即:www.blog.com/article/my-first-article#cmets
现在我只有 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); }
【问题讨论】:
标签: viewmodel anchor asp.net-mvc