Note that there are some explanatory texts on larger screens.

plurals
  1. POManipulating page scrolling when returning a View in an ASP.NET MVC site
    primarykey
    data
    text
    <p>I'm building an ASP.NET MVC site where I want one of the Views I return to be automatically scroll to a certain point.</p> <p>The part of the site where I want this to occur works sort of like a forum - there are "threads" that contain "posts". A user can either browse to the whole paginated thread or can browse to a specific post, using its ID. When a user browses to a specific post, I want to show the regular thread interface, then browse to the page that the post is on and scroll down to the post.</p> <p><strong>Is it possible to somehow automatically scroll down to a certain point when returning a View from an action in an ASP.NET MVC site?</strong> If so, how do I do this?</p> <p><em>NOTE: One solution to this problem that I've found is how Stack Overflow and the other Stack Exchange sites do it: each answer to a question can be linked to by adding <code>#ID</code> to the URL. If it's impossible to automatically scroll down when returning a View, I would implement this instead, but I don't understand how to use such an approach when there are multiple pages and the post in question isn't on the current page.</em></p> <hr> <p><strong>UPDATE:</strong></p> <p>Based on <a href="https://stackoverflow.com/questions/3243543/manipulating-page-scrolling-when-returning-a-view-in-an-asp-net-mvc-site/3243587#3243587" title="Chris&#39; answer">Chris' answer</a>, I'm currently planning to implement it with the URL looking like this: <code>example.com/forum/[ForumID]/thread/[ThreadID]/post/[PostID]#[PostID]</code>. In my Action, I figure out what page of the Thread the Post is on, and then I return all the Posts from that page to the View.</p> <p>However, I noticed something special in how Stack Overflow solves this problem. Try going to: <a href="https://meta.stackexchange.com/questions/57170" title="try going here">https://meta.stackexchange.com/questions/57170</a> - it ends up sending you to <a href="https://meta.stackexchange.com/questions/57155/gravatar-bugs-and-improvements-in-chat/57170#57170" title="it sends you here">https://meta.stackexchange.com/questions/57155/gravatar-bugs-and-improvements-in-chat/57170#57170</a>.</p> <p><strong>How is the above implemented?</strong> This is <strong><em>exactly</em> what I want to accomplish</strong>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload