现在的位置: 首页 > 综合 > 正文

Asp.net mvc实现通过下拉框选择页码后自动跳页

2012年08月30日 ⁄ 综合 ⁄ 共 1164字 ⁄ 字号 评论关闭

因为我们的分页 支持通过下拉框选择页码后自动跳页 有点儿像webform 的autopostback  而我们又是get 提交版的  需要解决一个问题 选择后自动跳页 需要带上以前的查询条件 不能跳完页以后 查询条件消失了

用一个隐藏的a 标签  这个a 标签生成的连接 保存了当前的查询条件等  他的页面数 显示成"*pageindex*  当我们选择下拉框跳页后 用选择的值 替换这个"*pageindex*  然后跳转到当前href 则解决了上述问题 

 上代码

    <text>跳转至</text>
    <select id="pageselect" onchange="selectchange()">
        @for (int i = 1; i <=@Model.TotalPageCount; i++)
            {
                var selected = "";
                if (i==Model.CurrentPageIndex)
                {
                    selected = "selected='selected'";
                }            
            <option value="@i" @selected>@i</option>
            }
    </select>
    
    {
        dict["PageIndex"] = "*pageindex*";
    }
    <a style="display:none" id="pagelink" href="@Url.RouteUrl(dict)" ></a>
    //  
    <script type="text/javascript">

            function selectchange() {
                var pageselect = document.getElementById("pageselect");
                var pageselectValue = pageselect.options[pageselect.selectedIndex].value;

                var linkdom= document.getElementById("pagelink");
                var href = linkdom.href;
                href = href.replace("*pageindex*", pageselectValue);

                window.location = href;
 
            }
    </script>
    
    <text>页</text>

抱歉!评论已关闭.