search - How to pass textbox value into query string in asp.net mvc -


Still another novice with ASP.NET MVC! Everything I want to do is for a search text box on my page, if I type something and click on the search, then the URL must be in the end to redirection, such as stack overflow,

  / I "text" name = "query" /> & Lt; A href = "???" Class = "searchButton" & gt; Search & lt; / A & gt;  

I have a function in this type of controller,

  public functioning search (string query) {}  
< P> Here's the route,

route. Map route ("search", "search", new {controller = "post", action = "search"});

Any interval can fill here :). Any comment appreciated.

Wrap it with form tag, set it to "GET", use input type ( Instead of 'A' tags), submit form 'submit' (instead of query 'A'), name text input as query (already done), parameter (already done) Accept the query as a string, Update the call process, ViewData.Model from the controller to the request process, return the proper view results That, you'll need to specify it if AJAX is used)

If you want to pass the query through the URL via the query string key / values.

I think that would be something like this:

  route. URL new {controller = "search", verb = "search"} // parameter defaults) with MapRoute ("search", // root name "search / {query}", // parameters);  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -