MVC3分页传2参

传值:  <td style="width:10%">  <a  href="/PostTypeView/GetPostTypeInfoByAea?areaid=@item.TN_Community.Areaid&&postTypeid=@item.PostTypeID"> @item.PostType.TypeName </a></td>

分页:<div>

    @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    / @Model.PageCount
    &nbsp;
    @if (Model.HasPreviousPage)
    {
     
        @Html.ActionLink("<<", "GetPostTypeInfoByAea", new { page = 1, currentFilter = ViewBag.CurrentFilter })
        @Html.Raw("&nbsp;");
       @Html.ActionLink("< 上一页", "GetPostTypeInfoByAea", new { page = Model.PageNumber - 1, currentFilter = ViewBag.CurrentFilter })

    }
    else
    {
        @:<<
        @Html.Raw("&nbsp;");
        @:< 上一页
    }
    &nbsp;
    @if (Model.HasNextPage)
    {
        @Html.ActionLink("下一页 >", "GetPostTypeInfoByAea", new { page = Model.PageNumber + 1, currentFilter = ViewBag.CurrentFilter })
        @Html.Raw("&nbsp;");
        @Html.ActionLink(">>", "GetPostTypeInfoByAea", new { page = Model.PageCount, currentFilter = ViewBag.CurrentFilter })
    }
    else
    {
        @:下一页 >
        @Html.Raw("&nbsp;")
        @:>>
    }
    
</div>

Controller:部分:

[ValidateInput(false)]
        public ViewResult GetPostTypeInfoByAea (string currentFilter, string searchString, int? page)
        {
          

            if (Request.QueryString["areaid"] != null)
            {   
               var areaid = Guid.Parse(Request.QueryString["areaid"]);
               var postTypeID = Guid.Parse(Request.QueryString["postTypeid"]);
               Session["areaid"] = areaid;
               Session["postTypeid"] = postTypeID;

               
                if (Request.HttpMethod == "GET")
                {
                    searchString = currentFilter;
                }
                else
                {
                    page = 1;
                }
                ViewBag.CurrentFilter = searchString;
                var TN_Post = db.TN_Post.Where(c => c.TN_Community.Areaid == areaid && c.PostTypeID==postTypeID).OrderByDescending(em => em.Views).ToList();
                if (!string.IsNullOrEmpty(searchString))
                {
                    TN_Post = TN_Post.Where(e => e.PostTitle.Contains(searchString)).ToList();
                }
                int pageSize = 10;
                int pageIndex = (page ?? 1) - 1;
                return View(TN_Post.ToPagedList(pageIndex, pageSize));
            

            }
            else
            {
                var id =Guid .Parse ( Session["areaid"].ToString());
                var tid =Guid .Parse ( Session["postTypeid"].ToString());
                if (Request.HttpMethod == "GET")
                {
                    searchString = currentFilter;
                }
                else
                {
                    page = 1;
                }
                ViewBag.CurrentFilter = searchString;
                  var TN_Post = db.TN_Post.Where(c => c.TN_Community.Areaid == id && c.PostTypeID == tid).OrderByDescending(em => em.Views).ToList();
                if (!string.IsNullOrEmpty(searchString))
                {
                    TN_Post = TN_Post.Where(e => e.PostTitle.Contains(searchString)).ToList();
                }
                int pageSize = 10;
                int pageIndex = (page ?? 1) - 1;
                return View(TN_Post.ToPagedList(pageIndex, pageSize));

            }
                              
            

要点用Session为载体
           
        }

posted @ 2011-09-05 16:53  指间缘  阅读(385)  评论(0编辑  收藏  举报