I have the following form
<form name="SearchForm" method="post" id="SearchForm" action="/Search/">
And the following button
<input type="button" onclick="javascript:document.SearchForm.submit();" class="btn-leftsearch">
On clicking this button, the form submits and calls this method
[HttpPost]
public ActionResult Index(string querystring)
{
return View();
}
Of course querystring is null. I want to pass querystring or preferably something else representing the fields in the form to the controller. I have tried playing with the action attribute in the form tag. I have tried to add the data to the onclick method in the button. Nothing is working. All I want to do is pass some data like this
Search?pri=all&amenity=pool etc
In the controller I would have something like
[HttpPost]
public ActionResult Index(string pri, List<string> amenities)
{
...
}
Can someone tell me how I can pass this data to the view?
I would like to suggest you that you can use the following code snip to resolve you problem.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection collection)
{
string valueFromNameTextBox = collection["name"];
}
on the collection please put the name of the search text box. You wil get the actual entered value. You can index into this collection with the names of all the inputs on the form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With