Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a view to post to a different controller MVC

Tags:

c#

asp.net-mvc

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?

like image 758
Kayra Avatar asked Dec 18 '25 03:12

Kayra


1 Answers

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>
}
like image 92
Darin Dimitrov Avatar answered Dec 20 '25 00:12

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!