3

I have a search bar on my Home-Index page:

<p>
    Find by name: @Html.TextBox("SearchString")  
    <input type="submit" value="Search" />
</p>

I need to submit this string into my code controller and take the user to the Code-Index page using the code controller, rather than the home controller. It seems the parameter is not enough for it to pick it up:

public ViewResult Index(string sortOrder, string searchString)
{
}

How would I go about this?

1
  • You should be able to just post the form to the controller you want to use...Could you add the rest of your form HTML? Commented Jan 28, 2013 at 16:52

1 Answer 1

14

Wrap it in a form and specify the controller and the action you want to submit to:

@using (Html.BeginForm("Index", "SomeOtherControllerName"))
{
    <p>
        Find by name: @Html.TextBox("SearchString")  
        <input type="submit" value="Search" />
    </p>
}
Sign up to request clarification or add additional context in comments.

1 Comment

saw the mvc tag and was wondering where Mr.Dimitrov was :) +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.