日期:2014-05-17  浏览次数:20495 次

asp.net mvc3 查询分页出现问题
我做了一个这样子的视图:


我的代码是这样的:

public ActionResult StudentList(string theGrade,
            string theMajor, string theName, string theNo, int page = 1)
        {
            AllStudentListModel viewModel = new AllStudentListModel
            {
                AllStudent = businessLogic.GetAllStudentInfo(theGrade, theMajor, theName, theNo)
                .Skip((page - 1) * pageSize).Take(pageSize),
                pageInfo = new PagingModel
                {
                    CurrentPage = page,
                    ItemsPerPage = pageSize,
                    TotalItems = businessLogic.GetAllStudentInfo(theGrade, theMajor, theName, theNo).Count()
                }
            };
            return View(viewModel);
        }



出现问题的情况是:
当我输入了一个查询条件,比如年级输入:2015
那么theGrade这个参数可以接受到2015,所以刷新之后可以得到正确的第一页结果

但是当我按第二页,重定向的url是 /StudentList?page=2 
而我希望是转到 /StudentList?page=2&theGrade=2015
怎么把theGrade这个参数保留下来??因为网页刷新后<input id="theGrade">的内容就没有了


------解决方案--------------------
建议楼主试试用我写的免费分页控件MvcPager:http://www.webdiyer.com/mvcpager/