Reputation: 1407
I have a view for a blog post that return a view model with the post and the comments, and an anchor point at the end of the page where the comment form is.
After i submit the comment form, i want the POST method to return the View() but with the anchor point in the link
ie : www.blog.com/article/my-first-article#comments
right now i only have www.blog.com/article/my-first-article and in order to view the Validation Errors you must scroll down to the comment.
Any Ideas?
Thanks, Alex
[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); }
Upvotes: 1
Views: 509
Reputation: 1731
Think might be a little low tech but it might work:
return Redirect("www.blog.com/article/my-first-article#comments");
Upvotes: 1