Ignore querystring value when posting form values to Action method
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 开发者_JAVA百科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.
精彩评论