• 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为载体
               
            }

  • 相关阅读:
    Struts2学习笔记:DMI,多个配置文件,默认Action,后缀
    Sturts2中Action的搜索顺序
    配置Struts2后运行jsp出现404的解决方法
    Tomcat服务器启动后访问localhost:8080显示404的原因
    Error:Cannot find bean: "org.apache.struts.taglib.html.BEAN" in any scope
    Missing message for key "xxx" in bundle "(default bundle)" for locale zh_CN
    jQuery添加删除
    jQuery的offset、position、scroll,元素尺寸、对象过滤、查找、文档处理
    jQuery_$方法、属性、点击切换
    jQuery选择器
  • 原文地址:https://www.cnblogs.com/zhijianyuan/p/2167715.html
Copyright © 2020-2023  润新知