博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MVC3分页传2参
阅读量:4957 次
发布时间:2019-06-12

本文共 2391 字,大约阅读时间需要 7 分钟。

传值:  <td style="width:10%">  <a  href=""> @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为载体

           
        }

转载于:https://www.cnblogs.com/zhijianyuan/archive/2011/09/05/2167715.html

你可能感兴趣的文章
unity, editable mesh
查看>>
android check box 自定义图片
查看>>
UVA 11044
查看>>
mysq找不到pid无法正常启动
查看>>
php实现抓取网站百度快照和百度收录数量的代码实例
查看>>
Qt那点事儿(三) 论父对象与子对象的关系
查看>>
jar 命令 打包装class文件的文件夹
查看>>
node.js express配置允许跨域
查看>>
set调用add报错:
查看>>
四轴飞行器1.2.1 RT-Thread 环境搭建
查看>>
choose&&char与char*区别
查看>>
51nod 1021 石子归并
查看>>
实验二:ICMP重定向攻击
查看>>
C/C++判断文件是否存在
查看>>
基础总结1
查看>>
随机算法
查看>>
洛谷 P1443 马的遍历
查看>>
AutoMapper中的Map和DynamicMap——高手注重细节,思考和总结
查看>>
html5离线应用application cache
查看>>
sqlserver 获取实例上用户数据库的数据字典
查看>>