I have the following code in controller:
public ActionResult SearchPage() {
return View();
}
[HttpPost]
public ActionResult Search( string option, string text ) {
// how to get request values-> and then I don't need the above parameters
ViewData["Results"] = _some.Search(option, text); //option and text should be from Request
return RedirectToAction( "SearchPage" );
}
and the SearchPage code:
<form action="<%=Url.Action("Search","Persons")%>" method="post" name="search-form">
<select name="search-option" id="search-option">
<option value="category">Category</option>
<option value="discipline">Discipline</option>
<option value="manufacturer">Manufacturer</option>
</select>
<input type="text" name="keyword" id="keyword" />
<input type="submit" name="submit" id="submit" value="Search" />
</form>
<% if ( ViewData["Results"] != null ) {
%>
<p>Test</p>
<%
}
%>
How to get the values submitted (the value from selectbox and the text from input text) with HttpRequest class ?
Thanks
First thing, you should have something like
and
You can’t use the character “-” in your view’s parameters because you can’t translate that in an automatically mapped parameter for your action.
That being said, if you don’t want to use action parameters for this one you can use something like: