Code
//页面是这样用的。。。。主要是要传递多个ViewData.Model
<% Html.RenderPartial("NewsListUserControl", ViewData["ViewDataAsc"]); %>
<br />
<% Html.RenderPartial("NewsListUserControl", ViewData["ViewDataDesc"]); %>
//具体的用户控件是这样的
<h2>新闻列表</h2>
<%
//var vd = new ViewDataDictionary();
foreach ( eg_news m in (Model as List<eg_news> ))
{
//var md = Model.
%>
<li><% =Html.ActionLink(m.news_title, "NewsDetail", "News", new { id = m.news_id },null)%></li>
<%
}%>
<br />
<% =Html.ActionLink("上一页","NewsList","News",new{pageCurrent=ViewData["pagePrev"]},null) %>
<% =Html.ActionLink("下一页", "NewsList", "News", new {pageCurrent = ViewData["pageNext"] }, null)%>
//分页我是用url传递参数的,问题是,当一个页面有多个这个用户控件的时候,我如何区分这个参数?或者说有动态的参数调用后台的controls么?
问题补充:
如果一个页面存在多个用户控件的时候,如何区分是哪个页面传递的翻页信息??或者说我这个设计本来就是错了的??
//用户控件内容
<%@ Import Namespace="Site.Models" %>
<h2>新闻列表</h2>
<%
//var vd = new ViewDataDictionary();
foreach ( eg_news m in (Model as List<eg_news> ))
{
//var md = Model.
%>
<li><% =Html.ActionLink(m.news_title, "NewsDetail", "News", new { id = m.news_id },null)%></li>
<%
}%>
<br />
<% =Html.ActionLink("上一页","NewsList","News",new{pageCurrent=ViewData["pagePrev"]},null) %>
<% =Html.ActionLink("下一页", "NewsList", "News", new {pageCurrent = ViewData["pageNext"] }, null)%>
//调用方法
<% Html.RenderPartial("NewsListAdminUserControl", ViewData["ViewDataAsc"]); %>
<br />
<% Html.RenderPartial("NewsListAdminUserControl", ViewData["ViewDataDesc"]); %>
//后台的control代码
int pageSize = 3, AllCount = _db.eg_news.Count();
int pageCount = 0;
if ((AllCount % pageSize) > 0)
{
pageCount = (AllCount - (AllCount % pageSize)) / pageSize + 1;
}
else
{
pageCount = AllCount / pageSize;
}
int pageCurrent = (Request["pageCurrent"] == null ? 1 : Convert.ToInt32(Request["pageCurrent"].ToString()));
if (pageCurrent == null || pageCurrent == 1)
{
ViewData["pagePrev"] = 1;
ViewData["pageNext"] = 2;
pageCurrent = 1;
}
else
{
//ViewData.ModelState.AddModelError
if ((pageCurrent - 1) <= 0)
{
pageCurrent = 1;
ViewData["pagePrev"] = 1;
}
e