views:

44

answers:

1

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 SearchController returns "your search term was test"

+2  A: 

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...

Bertvan
Just to be clear the SearchQuery is the text the user enters.And I already search the internet without any luck, but I just need a simple example.
gulbaek
http://stephenwalther.com/blog/archive/2009/03/03/chapter-6-understanding-html-helpers.aspxScroll down untill you see "Listing 2". And go read a book on ASP.NET MVC now :)
Bertvan
Almost thereAdded the following codecontext.MapRoute( "Search", "Search/{searchTerm}/", new { controller = "Search", action = "Index", searchTerm = UrlParameter.Optional } ); public string Index(string searchTerm) { return "your search term was "+ searchTerm; }This makes it possible for me to enter an url like /Search/Hello/ and get a searchterm = "Hello" which is great.
gulbaek
<% using (Html.BeginForm("Index", "Search", new { area = "eCommerce" }, FormMethod.Post, new { searchTerm = "searchTerm" })) %><% { %><input name="searchTerm" type="search" results="5" placeholder="Produkt søgning" autofocus /><input type="submit" value="Søg"><% } %>My submit for, worket, but it don't use and url like /Search/Hello/ but my Index(string searchTerm) still get's the correct input, any idea of what im doing wrong?
gulbaek
please update your question, it's impossible to read code in a comment
Bertvan
Bertvan updatede the question, hope its more readable now.
gulbaek