我在我的页面中有表单,get和post,我想在我的get表单上添加页签。所以我不能翻阅结果..
我遇到的问题是,当我移动到第二页时,它没有显示任何内容。
我正在使用这个库进行分页..http://stephenwalther.com/Blog/archive/2008/09/18/asp-net-mvc-tip-44-create-a-pager-html-helper.aspx
这是我的操作代码。
[AcceptVerbs("GET")]
public ActionResult SearchByAttraction()
{
return View();
}
[AcceptVerbs("POST")]
public ActionResult SearchByAttraction(int? id, FormCollection form)
{....
}这就是我在get表单中使用的页面
<%= Html.Pager(ViewData.Model)%> //但是当我这样做时,它转到这个方法AcceptVerbs("GET")公共ActionResult SearchByAttraction()
而不是转到这个
AcceptVerbs("POST")公共ActionResult SearchByAttraction(int?id,FormCollection表单)
从某种意义上讲..但是我真的想不出还有什么其他的办法
任何帮助都将不胜感激..
谢谢
发布于 2008-12-15 19:34:42
我建议不要通过HTTP POST进行分页。页面和搜索条件是查询字符串的两个很好的例子。将这些值放在查询字符串中&让它加载您的操作参数。
想想看。你可以在谷歌上搜索“派”,导航到第14页,复制链接并发送给你的祖母。当您的分页/搜索仅适用于表单帖子时,您不能这样做。
发布于 2008-12-15 17:10:06
当然,它将命中SearchByAttraction的GET版本,因为使用此控件将有一个链接作为输出。
所以你需要做的是:
1. make form on the page:
<form id="myForm" action="your/url" method="post">
<input type="hidden" name="page" />
<input type="hidden" name="your_param1" />
<input type="hidden" name="your_param2" />
<input type="hidden" name="your_paramN" />
</form>
2. make changes to pager - it should produce something like that:
<ul id="pager">
<li><a href="url/as/was/created/by/pager" onclick="return submitMyForm(1);">1</a></li>
<li><a href="url/as/was/created/by/pager" onclick="return submitMyForm(2);">2</a></li>
<li><a href="url/as/was/created/by/pager" onclick="return submitMyForm(3);">3</a></li>
</ul>
3. add simple javascript function on the page:
<script language="javascript" type="text/javascript">
function submitMyForm(page) {
var form = document.forms["myForm"];
form.elements["page"].value = page;
form.submit();
return false;
}
</script>您将能够访问POST版本,因为单击该链接将使用POST请求在服务器上提交表单。
发布于 2008-12-15 18:09:17
试试这个:
[AcceptVerbs("GET")]
public ActionResult SearchByAttraction(int? id)
{
return View();
} id应包含需要显示的页码。
如果使用这种方法丢失了表单值,则需要更改Html.Pager方法以将每个操作链接呈现为表单提交链接。
https://stackoverflow.com/questions/368956
复制相似问题