What is the solution for this problem? :)
To write a custom Html.BeginForm helper which will behave as you want:
using System;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
public static class FormExtensions
{
public static IDisposable MyBeginForm(this HtmlHelper html, string action, string controller, FormMethod method)
{
var routeValues = new RouteValueDictionary();
var query = html.ViewContext.HttpContext.Request.QueryString;
foreach (string key in query)
{
routeValues[key] = query[key];
}
return html.BeginForm(action, controller, routeValues, FormMethod.Get);
}
}
and then in your view use this custom helper instead of the default one:
@using (Html.MyBeginForm(null, null, FormMethod.Get))
{
...
}
and if you don't want to be writing custom helper (not recommended) you could also hurt your views by writing the following horror that will capture current query string parameters:
@using (Html.BeginForm(null, null, new RouteValueDictionary(Request.QueryString.Keys.Cast<string>().ToDictionary(key => key, key => (object)Request.QueryString[key])), FormMethod.Get))
{
...
}