电话
13363039260
方法1:通过栏目id和信息id调用,演示代码如下:
@{ var infoData = Html.InfoData(); int infoId =Html.CurrentInfoId(); int columnId = infoData.ColumnId; //获取当前信息的栏目id var prevData = Html.InfoDataPrevious(columnId,infoId); var nextData = Html.InfoDataNext(columnId,infoId); } <div> @if (prevData != null) { <div><span class="text-gray">上一篇:</span><a href="@prevData._InfoDataUrl">@prevData.Title</a></div> } @if (nextData != null) { <div><span class="text-gray">下一篇:</span><a href="@nextData._InfoDataUrl">@nextData.Title</a></div> } </div>
注:早期版本不支持@prevData._InfoDataUrl和@nextData._InfoDataUrl这样的属性,替代方式:
.... @if (prevData != null) { <div><span>上一篇:</span><a href="@Html.InfoDataUrl(columnId,(int)prevData.Id)">@prevData.Title</a></div> } @if (nextData != null) { <div><span>下一篇:</span><a href="@Html.InfoDataUrl(columnId,(int)nextData.Id)">@nextData.Title</a></div> }
方法2:通过表名和信息Id调用,演示代码如下:
@{ var infoData = Html.InfoData(); int infoId =Html.CurrentInfoId(); var prevData = Html.InfoDataPrevious("news",infoId); //上一篇数据 var nextData = Html.InfoDataNext("news",infoId); //下一篇数据 } <div> @if (prevData != null) { <div><span class="text-gray">上一篇:</span><a href="@prevData._InfoDataUrl">@prevData.Title</a></div> } @if (nextData != null) { <div><span class="text-gray">下一篇:</span><a href="@nextData._InfoDataUrl">@nextData.Title</a></div> } </div>
实例1:只显示当前同一个栏目下的上一篇和下一篇数据,演示代码如下:
@{ var infoData=Html.InfoData(); int infoId =Html.CurrentInfoId(); int columnId=infoData.ColumnId; //参数3和参数4分别为sql条件和sql参数 var prevData=Html.InfoDataPrevious(columnId,infoId,"columnId=@columnId",new{columnId=columnId}); var nextData=Html.InfoDataNext(columnId,infoId,"columnId=@columnId",new{columnId=columnId}); } <div> @if (prevData!=null) { <div><span class="text-gray">上一篇:</span><a href="@prevData._InfoDataUrl">@prevData.Title</a></div> } @if (nextData!=null) { <div><span class="text-gray">下一篇:</span><a href="@nextData._InfoDataUrl">@nextData.Title</a></div> } </div>
实例2:调用图片,演示代码如下:
@{ var infoData = Html.InfoData(); int infoId =Html.CurrentInfoId(); int columnId = infoData.ColumnId; //获取当前信息的栏目id var prevData = Html.InfoDataPrevious(columnId, infoId); var nextData = Html.InfoDataNext(columnId, infoId); } <div class="row line-height-2"> @if (prevData != null) { var prevThumbnail = prevData.Thumbnail; //获取缩略图路径 if (string.IsNullOrEmpty(prevThumbnail)) { //没有图片时候显示标题,或自定义默认图片,可以自行修改逻辑 <a href="@prevData._InfoDataUrl">@prevData.Title</a> } else { <a href="@prevData._InfoDataUrl"><img src="@prevThumbnail" /></a> } } @if (nextData != null) { var nextThumbnail = nextData.Thumbnail; //获取缩略图路径 if (string.IsNullOrEmpty(nextThumbnail)) { <a href="@nextData._InfoDataUrl">@prevData.Title</a> } else { <a href="@nextData._InfoDataUrl"><img src="@nextThumbnail" /></a> } } </div>