Asp.net mvc 2 Search form in Partial View
Hi could someone make a small example for me.
I wanna create a partial view with a textbox and a submit button. When the user hits the submit button, I want to redirect to the following url
/Search/SearchQuery/
UPDATE
//This is my searchBox.ascx
<% using (Html.BeginForm("Index", "Search", new { area = "eCommerce" }, FormMethod.Post, new { searchTerm = "searchTerm" })) %>
<% { %>
<input name="searchTerm" type="search" results="5" placeholder="Product search" autofocus />
<input type="submit" value="Search">
<% } %>
And here is my SearchController
public string Index(string searchTerm)
{
return "your search term was "+ searchTerm;
}
And finally my MapRoute
context.MapRoute(
"Search",
"Search/{searchTerm}/",
new { controller = "Search", action = "Index", searchTerm = UrlParameter.Optional }
);
Now its possible to use /Search/searcTerm/ but when I use my searchBox it just redirects /Search but my SearchCont开发者_如何学Pythonroller returns "your search term was test"
Look at
Html.BeginForm("SearchQuery", "Search")
{
}
Put your text field in between that statement. Put a button in there as well.
That's it, basically, plenty of examples around...
精彩评论