我有一個顯示用戶評論的網頁。我默認頁面顯示最近10次。在底部,當使用點擊「顯示更多」時,下面會顯示10條評論。用戶可以多次點擊該按鈕,每次底部顯示10個註釋。問題是用戶必須再次向下滾動。我想使用錨點來選擇最後顯示的評論。如何在MVC 4中使用HTML錨?
在我看來,我有:
@{ int i = 1; }
@foreach (var item in Model) {
<div class="Comment" id="[email protected]">
@Html.DisplayFor(modelItem => item.CommentText)
</div>
i++;
}
@{int numCommentsToDisplay = 10;}
@if (Session["numCommentsToDisplay"] != null) {
numCommentsToDisplay = Convert.ToInt32(Session["numCommentsToDisplay"]);
}
@Html.ActionLink("Show More", "Index", new { numCommentsToDisplay = numCommentsToDisplay + 10 })
而且我控制器包含:
public ActionResult Index(int numCommentsToDisplay = 10) {
this.HttpContext.Session.Add("numCommentsToDisplay", numCommentsToDisplay.ToString());
var latestComments = db.Comments.Take(numCommentsToDisplay).OrderByDescending(c => c.TimeStamp).ToList();
return View(latestComments);
}
當用戶點擊「顯示更多」,第一次,20條評論將被顯示,如何我可以選擇第11條評論嗎?我已經設定的ID和手動導航到http://localhost:49208/Comment?numCommentsToDisplay=20#Comment-11
的伎倆
感謝
我無法得到您的答案。這是通過HtmlAttributes?哪個不會通過我的錨?或者我錯過了什麼? – Rodders
請向您的代碼片段添加一些解釋。 –