1
我有一個博客文章的視圖返回一個視圖模型的帖子和評論,並在評論表單的頁面末尾的錨點。asp MVC返回與html錨查看模型
後,我提交的評論的形式,我想POST方法返回視圖(),但在鏈接
即錨點: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); }