title: How can I use HTML Anchors in MVC 4?
body: <p>I have a web page that displays user comments. I default the page to display the most 10 recent. At the bottom, when the use clicks 'Show More', 10 more comments will appear underneath. User can click the button multiple times and 10 more comments will display at the bottom each time. The problem is the user has to scroll down again. I want to use anchors to select the last comment displayed. </p>
  
  <p>In my view, I have:</p>
  
  <pre><code>@{ int i = 1; }
  @foreach (var item in Model) {
      &lt;div class="Comment" id="Comment-@i"&gt;
          @Html.DisplayFor(modelItem =&gt; item.CommentText)
      &lt;/div&gt;
  
      i++;
  }
  
  @{int numCommentsToDisplay = 10;}
  @if (Session["numCommentsToDisplay"] != null) {
      numCommentsToDisplay = Convert.ToInt32(Session["numCommentsToDisplay"]); 
  }
  
  @Html.ActionLink("Show More", "Index", new { numCommentsToDisplay = numCommentsToDisplay + 10 })
  </code></pre>
  
  <p>And my controller contains:</p>
  
  <pre><code> public ActionResult Index(int numCommentsToDisplay = 10) {
       this.HttpContext.Session.Add("numCommentsToDisplay", numCommentsToDisplay.ToString());
       var latestComments = db.Comments.Take(numCommentsToDisplay).OrderByDescending(c =&gt; c.TimeStamp).ToList();
  
       return View(latestComments);
   }
  </code></pre>
  
  <p>When the user clicks 'Show More' for the first time, 20 comments will be shown, how can I select the 11th comment? I have already set the IDs and manually navigating to <code>http://localhost:49208/Comment?numCommentsToDisplay=20#Comment-11</code> does the trick</p>
  
  <p>Thanks</p>