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)?
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.
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.
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.
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.
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>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With