I am working with mvc4 and have a field where a user can enter some text in to an input field which gets passed to the url and redirect to another page eg. /search/<>
My form is as follows but redirects as query string.
<form class="search" action="@Url.Action("Index", "Search")">
<div>
<input name="q" value="" type="search" />
<input type="image" name="btn" value="search" src="@Url.Content("/image1.jpg")" />
</div>
</form>
Any idea how I could alter my form to pass the inputed value to input “q” to the url.
You could use a
GETmethod:You could also generate this exact same markup using the
Html.BeginFormhelper which is designed for this purpose:When you use the GET method all input element values will be sent in the query string when the form is submitted.
And if you want to append the search string in the path portion of the url instead of using a query string parameter I invite you to read the
following blog postfrom Scott Hanselman. I will quote only his conclusion: