将表单值发布到 Action 方法时忽略查询字符串值
我有一个带有字段和提交按钮的“搜索”表单。返回的结果与呈现锚元素的分页器控件一起显示。
例如,我的表单将包含字段 company
和 product
我将有一个类似的 Action 方法
public ActionResult Index(string company, string product, int? page)
{
var model = GetModel(company, product, page ?? 1);
return View(model);
}
,视图将显示结果并生成分页链接,例如。 ..
<a href="/?company=Microsoft&product=Windows&page=2">2</a>
所以基本上寻呼机重新提交相同的查询,但带有页面参数。
我遇到的问题是,如果我使用分页器控件转到第 2 页,然后提交新的搜索查询,则页面操作参数将映射到上一个分页操作中的页面查询字符串参数,而我需要将其重置为无效的。否则,我可能会到达只有一页的查询结果列表的第 2 页。
我该如何解决这个问题?
还有一个相关的问题,有没有办法提交分页器参数信息而不将其放入查询字符串中?不幸的是我不能使用javascript。我认为这是不可能的,但我想我会检查一下。
I have a "search" form with fields and a submit button. The returned results are displayed along with a pager control which renders anchor elements.
So for example my form would have fields company
and product
And I'd have an Action method something like
public ActionResult Index(string company, string product, int? page)
{
var model = GetModel(company, product, page ?? 1);
return View(model);
}
and the view will show the results and generate paging links like for example...
<a href="/?company=Microsoft&product=Windows&page=2">2</a>
So basically the pager re-submits the same query but with a page parameter.
The problem I'm having is that if I go to page 2 using the pager control and then submit a new search query, the page Action parameter will get mapped to the page querystring parameter from the previous paging action, whereas I need it reset to null. Otherwise I can end up on page 2 of a query results list which only has one page.
How do I fix this?
And a related question, is there any way to submit the pager parameter information without putting it in the querystring? I can't use javascript unfortunately. I don't think this is possible but thought I'd check.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论