I am trying to create a simple search box that results in something like http://www.example.com/Search?s=searchTerm I have the routing setup so that it accepts a url like this, and does the right thing. The problem I’m having is getting the form to create the querystring. I have tried many variations of:
<% using (Html.BeginForm("Search", "Home", FormMethod.Get, new { ???? })) {%>
<input id="submitSearch" class="searchBox" type="text" runat="server"/>
<input type="submit" value="Search" /> <%} %>
I’m not sure how to setup the Html.BeginForm so it grabs the submitSearch value and passes it to /Search?s=valueHere. This seems like I am missing something easy.
You need to set
nameon the input box tos.Also, note that I changed the
idtosas well, since common practice is to have the same value fornameandid. However, it is only thenameattribute that affects the query string name in the request.And as David noted in a comment, the
runat="server"is not needed in ASP.NET MVC.