分享

ASP.NET MVC 使用FCKEditor的分页符进行文章分页HMCWEB.net 专...

 yyrb 2011-04-13
01 /// <summary>
02 ///文章分页函数
03 /// </summary>
04 /// <param name="content">文章内容</param>
05 /// <param name="currentPage">当前页码</param>
06 /// <param name="pageUrl">当前页面地址</param>
07 protected String[] ArticlePage(string content, int currentPage, string pageUrl)
08 {
09     String[] result = new String[2];
10     int pageCount = 0;//页数
11     content = content.Replace("<div style=\"page-break-after: always\"><span style=\"display: none\"> </span></div>", "[--page--]");//FCK在IE中生成的默认分页符,替换为自定义分页符
12     string[] tempContent = System.Text.RegularExpressions.Regex.Split(content, "\\u005B--page--]"); //取得分页符 "\\u005B"为"["的转义
13     pageCount = tempContent.Length;
14     string outputContent = "";//要输出的内容
15     if (pageCount <= 1)
16     {
17         outputContent = content; //文章内容
18         result[0] = String.Empty;
19     }
20     else
21     {
22         string pageStr = "";//分页字符串                
23         if (currentPage != 1)
24         {
25             pageStr += "<a class='prev' href =" + pageUrl + "_" + (currentPage - 1) + ".html> </a>";
26         }
27         for (int i = 1; i <= pageCount; i++)
28         {
29             if (i == currentPage)
30                 pageStr += ("<span class='active'>[" + i + "]</span>");            
31             else
32                 pageStr += ("<a class='num' href =" + pageUrl + "_" + i + ".html>[" + i + "]</a>");
33         }
34         if (currentPage != pageCount)
35         {
36             pageStr += "<a class='next' href =" + pageUrl + "_" + (currentPage + 1) + ".html> </a>";
37         }
38         result[0] = pageStr;
39         outputContent = tempContent[currentPage - 1].ToString();
40     }
41     result[1] = outputContent;
42     return result;
43 }

 

 

Controller部分

01 public ActionResult Attractions(int id,int? pageid)
02 {
03          Pic_info picinfo = new PicDal().GetPic_infoByID(id);
04         String[] result = ArticlePage(picinfo.Pic_Context, pageid ?? 1, "/Attractions/list_" + id);
05         picinfo.Pic_Context = result[1];
06         ViewData["page_num"] = result[0];
07         ViewData["type"] = 1;
08         return View(picinfo);
09       
10 }


 


View页面:

01 <% Pic_info pic = Model as Pic_info;
02 if (pic != null)
03
04   %> 
05   <h3><%= pic.Pic_name%></h3>
06   <div>
07   <%= pic.Pic_Context%>
08   </div>
09  <div class="page_num"><%= ViewData["page_num"].ToString()%></div
10   <% } %>


 
 CSS样式:

 

01 .page_num
02 {
03     position:relative;
04     margin:0 auto;
05     width:300px;
06     margin-top:10px;
07 }
08  .prev,.next
09  {
10      height:21px;
11      width:69px;
12      display:block;
13      float:left;
14      margin:0 2px;
15      text-decoration:none;
16  }
17 .prev
18 {
19     background:url(images/page_up.gif) no-repeat;
20
21 .next
22 {
23     background:url(images/page_down.gif) no-repeat;
24 }
25 .count
26 {
27     float:left;
28     margin-right:40px;
29     margin-top:4px;
30     
31 }
32 .num,.active
33 {
34     float:left;   
35     font-size:14px;
36     text-decoration:none;
37     padding:2px 2px 0 2px;
38 }
39 .num
40 {
41    color:#000;
42 }
43 .num:hover
44 {
45      color:#0068BE;
46 }
47 .active
48
49     color: #0068BE;
50 }

 

预览:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多