In an MVC3 app, i have the following View:
@using (Html.BeginForm("Index", "Search", new {query = @Request.QueryString["query"]}, FormMethod.Post))
{
<input type="search" name="query" id="query" value="" />
}
When i type in the url “/Search?query=test”, Request.Querystring in my Index action reads out the search-value perfectly well (i have my routes set to ignore the Action in the url). When i type it in the seachbox, it hits the right action and controller (so the routing seems fine) but the querystring remains empty. What am i doing wrong?
The Problem is that you are look in the
Request.QueryStringcollection. But you are doing aPOSTso thequeryvalue is in theRequest.FormCollection. But i think you want your TextBox filled with the data so can do it like in my sample.Sample
But this is not the real MVC approach. You should create a ViewModel for that.
Model
View
Controller