Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Search Box on Layout.cshtml

Tags:

asp.net-mvc

I've created the search form and results from http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application which handles paging and sorting using the PagedList Nuget package.

What I need help with though, is how do I put the search form on my master page? (_layout.cshtml)?

like image 735
Robbie Mills Avatar asked Apr 22 '12 07:04

Robbie Mills


People also ask

How can add search box in ASP.NET MVC?

Right-click on the controller folder then select Add -> controller. Select MVC 5 Controller with read/write actions and click Add. Provide the controller a name. Click Add.

What is _layout Cshtml in MVC?

The file "_Layout. cshtml" represents the layout of each page in the application. Right-click on the Shared folder in Solution Explorer then go to "Add" item and click on "View". Now the View has been created.

What is _ViewStart Cshtml in MVC?

The _ViewStart. cshtml page is a special view page containing the statement declaration to include the Layout page. Instead of declaring the Layout page in every view page, we can use the _ViewStart page. When a View Page Start is running, the “_ViewStart. cshtml” page will assign the Layout page for it.

How do I display Cshtml?

Right click the Index. cshtml file and select View in Browser. You can also right click the Index. cshtml file and select View in Page Inspector.


1 Answers

put a from contains a Text box and a button and the form's action will be the search action

Ex code in the _layout.cshtml page

@using(Html.BeginForm("ActionName","ControllerName", FormMethod.Get))
{
    @Html.TextBoxFor(m => m.Query)

    <div>
        <input type="submit" value="Search" />
    </div>
}
like image 54
Nadeem Khedr Avatar answered Nov 02 '22 02:11

Nadeem Khedr