我有一个评论列表。客户希望每 10 条评论后有一个新页面,因此评论 11 将出现在第 2 页上,以此类推,直到他们获得的页面数。由于我在常规 .aspx.cs 页面上遇到的问题,因此在 .ashx 页面上形成了评论。简而言之,我该如何做到这一点?
这是 .ashx 页面的代码:
public void ProcessRequest (HttpContext context)
{
// ****************************************
if (context.Request["postform"] == "1")
{
videomessage myVideoMessage = new videomessage();
myVideoMessage.video_id = context.Request["video_id"];
myVideoMessage.first_name_submitter = context.Request["first_name_submitter"];
myVideoMessage.last_initial_submitter = context.Request["last_initial_submitter"];
myVideoMessage.message = context.Request["message"];
myVideoMessage.status = "0";
myVideoMessage.Save();
}
// ****************************************
// ****************************************
StringBuilder myStringBuilder = new StringBuilder();
// PULL VIDEOMESSAGES FOR VIDEO_ID
videomessage[] myCommentsList = new videomessage().Listing("video_id", context.Request["video_id"], "entry_date" , "DESC");
// FORM COMMENTS IF MORE THAN ONE COMMENT EXISTS
foreach (videomessage tmpMessage in myCommentsList)
{
if (tmpMessage.status == "0" || tmpMessage.status == "1")
{
myStringBuilder.Append("<div class=\"comment_box\">");
myStringBuilder.Append("<p class=\"comment_date\">");
myStringBuilder.Append(Utility.FormatShortDate(tmpMessage.entry_date) + " " + tmpMessage.first_name_submitter + " " + tmpMessage.last_initial_submitter + "." + "</p>");
if (!String.IsNullOrEmpty(tmpMessage.message))
{
myStringBuilder.Append("<p>" + tmpMessage.message + "</p>");
myStringBuilder.Append("</div>");
}
}
}
string return_str = myStringBuilder.ToString();
// IF NO COMMENTS RETURN THIS
if( String.IsNullOrEmpty(return_str) ) return_str = "<p>No comments currently exist for this video.</p>";
// ****************************************
// RETURN STRING
context.Response.ContentType = "text/plain";
context.Response.Write(return_str);
}
我知道需要涉及一些数学并将其分配给变量,但我对 .NET 仍然很陌生,因此将不胜感激。
提前致谢!