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

 1.此方法为核心方法

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
/// <summary>
/// 文章分页函数
/// </summary>
/// <param name="content"> 文章内容 </param>
/// <param name="currentPage"> 当前页码 </param>
/// <param name="pageUrl"> 当前页面地址 </param>
protected String[] ArticlePage( string content, int currentPage, string pageUrl)
{
String[] result
= new String[ 2 ];
int pageCount = 0 ; // 页数
content = content.Replace( " <div style=\ " page - break - after: always\ " ><span style=\ " display: none\ " >&nbsp;</span></div> " , " [--page--] " ); // FCK在IE中生成的默认分页符,替换为自定义分页符
string [] tempContent = System.Text.RegularExpressions.Regex.Split(content, " \\u005B--page--] " ); // 取得分页符 "\\u005B"为"["的转义
pageCount = tempContent.Length;
string outputContent = "" ; // 要输出的内容

if (pageCount <= 1 )
{
outputContent
= content; // 文章内容
result[ 0 ] = String.Empty;

}
else
{
string pageStr = "" ; // 分页字符串
if (currentPage != 1 )
{
pageStr
+= " <a class='prev' href = " + pageUrl + " _ " + (currentPage - 1 ) + " .html>&nbsp;</a> " ;
}

for ( int i = 1 ; i <= pageCount; i ++ )
{
if (i == currentPage)
pageStr
+= ( " <span class='active'>[ " + i + " ]</span> " );
else
pageStr
+= ( " <a class='num' href = " + pageUrl + " _ " + i + " .html>[ " + i + " ]</a> " );
}

if (currentPage != pageCount)
{
pageStr
+= " <a class='next' href = " + pageUrl + " _ " + (currentPage + 1 ) + " .html>&nbsp;</a> " ;
}
result[
0 ] = pageStr;
outputContent
= tempContent[currentPage - 1 ].ToString();
}
result[
1 ] = outputContent;
return result;
}

 

Controller部分

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
public ActionResult Attractions( int id, int ? pageid)
{
Pic_info picinfo
= new PicDal().GetPic_infoByID(id);
String[] result
= ArticlePage(picinfo.Pic_Context, pageid ?? 1 , " /Attractions/list_ " + id);
picinfo.Pic_Context
= result[ 1 ];

ViewData[
" page_num " ] = result[ 0 ];
ViewData[
" type " ] = 1 ;
return View(picinfo);

}

 

View页面:

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
<% Pic_info pic = Model as Pic_info;
if (pic != null )
{
%>
< h3 ><%= pic.Pic_name %></ h3 >
< div >
<%= pic.Pic_Context %>
</ div >
< div class = " page_num " ><%= ViewData[ " page_num " ].ToString() %></ div >
<% } %>

 

 CSS样式:

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
.page_num
{
position
: relative ;
margin
: 0 auto ;
width
: 300px ;
margin-top
: 10px ;
}
.prev,.next
{
height
: 21px ;
width
: 69px ;
display
: block ;
float
: left ;
margin
: 0 2px ;
text-decoration
: none ;
}
.prev
{
background
: url(images/page_up.gif) no-repeat ;
}
.next
{
background
: url(images/page_down.gif) no-repeat ;
}
.count
{
float
: left ;
margin-right
: 40px ;
margin-top
: 4px ;

}
.num,.active
{
float
: left ;
font-size
: 14px ;
text-decoration
: none ;
padding
: 2px 2px 0 2px ;
}
.num
{
color
: #000 ;
}
.num:hover
{
color
: #0068BE ;
}
.active
{
color
: #0068BE ;
}

 

预览:

2010061911435372.jpg

 

 

 

转载于:https://www.cnblogs.com/weiqh/archive/2010/06/18/1760449.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值