• MVC3分页传2参


    传值:  <td style="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为载体
               
            }

  • 相关阅读:
    R--相关分布函数、统计函数的使用
    Spark Streaming
    统计与分布的相关知识
    Python--WebDriverWait+expected_conditions的一个应用
    Python+Selenium与Chrome如何进行完美结合
    Python+Selenium+Chrome 的一个案例
    python -使用Requests库完成Post表单操作
    JetBrains PyCharm 2018.2.4 x64 工具里如何安装bs4
    用JetBrains PyCharm 开发工具写一个简单python案例
    dom4j学习总结(一)
  • 原文地址:https://www.cnblogs.com/zhijianyuan/p/2167715.html
Copyright © 2020-2023  润新知