views:

46

answers:

2

a little problem for ya.

in master page i have a search input and link:

<input type="text" value="Searche..." name="txtSearche" id="txtSearche" style="vertical-align: middle; height:14px;" />
<%= Html.ActionLink("search", "Search", "Search", new{ searche = "txtSearche???what is here"}, null) %>

how can i write value in url "value" from input text and then get it in my search controller?

  [HttpGet]
        public ActionResult Search(string txtSearche)
        {
            try
            {
                SearchModel model = new SearchModel(txtSearche);
                if (txtSearche != null)
                {
                    return View(model);
                }
                else
                {
                    return View();
                }
            }

my biggest problem is here-> new{ searche = "txtSearche???what is here"} i dont know how to make this part working

+1  A: 
public ActionResult Search(string txtSearche, string searche) {

simple :) just put it in the parameters.

or you also can do string searche = Request["searche"] but in MVC, use the first option :)

Edit: ok i get what you want. you have an input form and you want to use this.

2 words: USE POST.

you are trying to make a get request in the URL what is actually a POST request. make a post, and then in your returning view, you can make the query come up in the URL as well.

the best thing is, make the postback, which will return navigate to the new URL with your searchquery in it with this

return RedirectToAction("Search", new { searche = txtSearche });
Stefanvds
what is string searce???? i need just a txtsearch or not???
Ragims
is new{ searche = "txtSearche"} in my html.actionlink correct?
Ragims
look, your question is not clear at all. what do you want? :) do you want an answer in your controller or in your page how to get something?
Stefanvds
A: 

if you were hoping on getting the textbox input then you need to put it in a form with a submit button. Then you will capture "txtSearche":

<% using(Html.BeginForm()) { %>
  <input type="text" value="Searche..." name="txtSearche" id="txtSearche" style="vertical-align: middle; height:14px;" />
  <input type="submit" value="search" />
<% } %>

You will need to make your action accept [HttpPost] though. Unless you make your form use the GET method

BritishDeveloper