I'm using ASP.NET adn have the following code in my view:
<% using(Html.BeginForm("Search", "Home", FormMethod.Get)) { %>
<%= Html.TextBox("searchText") %>
<input type="submit" value="Search" />
<% } %>
and in my controller I have:
public ActionResult Search(string searchText)
{
return View("Index");
}
If I have a breakpoint in the Search-action and examine the searchText argument it's always "" even if I type some text in the texbox. If I change the formmethod to POST it works as expected.
How can I read "searchText" when using http-GET?
Edit:
I had the following route
routes.MapRoute(
"Search", // Route name
"Search/{searchText}", // URL with parameters
new { controller = "Home", action = "Search", searchText ="" } // Parameter defaults
);
and when I removed the default value of searchText(searchValue=""), then I got the correct value in my action. Why?