ASP.NET MVC 中的 Post Action 分页问题
我有一个页面,它在表单上获取多个参数并将它们发布到操作中。它返回许多需要分页的搜索结果。我的寻呼机使用 ActionLink;
<%= Html.ActionLink(i.ToString(), "Basic", new { page = (i - 1) })%>
结果按预期返回,但是当我单击第二页时,它会转到默认操作,而不是标有帖子的操作。表单值不会再次提交,第二页显示的结果是默认结果,未使用参数进行过滤。
我不知道如何解决这个问题?一种方法是将表单值保存到帖子的数据库中,并在默认操作中读回它们,但这似乎有点过分了。
谢谢你!
I have a page that takes a number of parameters on a form and posts them to an action. It returns a number of search results that need to be paged through. My pager uses ActionLink;
<%= Html.ActionLink(i.ToString(), "Basic", new { page = (i - 1) })%>
The results comeback as expected but when I click on page two it goes to the default Action, not the one marked with post. The form values do no get submitted again and the results that are shown for page two are the default results not filters with the parameters.
I am not sure how to solve this problem? One way was to save the form values into the database on the post and reading them back on the default action but it seems overkill.
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MVCContrib Grid 和 Pager 处理这种特定的场景。您可以自己编写,但我会推荐 Grid 和 Pager UI 帮助器。
http://mvccontrib.codeplex.com/
http://mvccontrib.codeplex.com/sourcecontrol/network/Show ?projectName=MVCContrib&changeSetId=4112aa6f6d84#src%2fMVCContrib%2fUI%2fPager%2fPager.cs
The MVCContrib Grid and Pager deals with this specific scenario. You can write your own but I would recommend both the Grid and Pager UI helpers.
http://mvccontrib.codeplex.com/
http://mvccontrib.codeplex.com/sourcecontrol/network/Show?projectName=MVCContrib&changeSetId=4112aa6f6d84#src%2fMVCContrib%2fUI%2fPager%2fPager.cs
我也遇到过同样的场景。
当用户单击“上一个”或“下一个”链接时,我选择使用 ajax 表单帖子进行分页。
下面的 javascript 函数可以做到这一点。
{
}
其中“searchResultPageNum”是一个隐藏字段,用于反映要加载的新页码。
'ajaxSearch' 是 ajax 表单 id,使用 AjaxForm 的 Html 帮助程序呈现。
'rvwLstFrmContainer' 是包含结果的 div。
社区!抱歉,关于格式错误的代码。无法正确发布
I came across the same scenario.
And I choose to do paging with ajax form posts when the user clicks on 'previous' or 'next' link.
Following javascript function does that.
{
}
Where 'searchResultPageNum' is a hidden field to reflect the new page number to load.
'ajaxSearch' is ajax form id, rendered using Html helper for AjaxForm.
'rvwLstFrmContainer' is the div that contains the results.
Community! Sorry, about illformatted code. Couldn't post it right