Database Reference
In-Depth Information
Solution
Let's say you have a model like the one in Figure 4-14 . In the solution, we are going to use three basic parts to build our
search page:
1.
A table to structure the query parameters.
2.
A WebGrid to present the results in Razor view.
3.
A Controller to incorporate the logic for the view.
In the database, you have a Customer table, which stores the Name, City and State information of all the
customers. The data model (schema) of the Customer table is shown in Figure 4-14 .
Figure 4-14. A model with a Customer entity
After having the Customer view model created, we need to write the view using Razor. In this view, we are using
WebGrid control to show the Customer records as mentioned in Listing 4-5.
Listing 4-5. Using WebGrid in MVC Razor View
@model EntityFrameworkRecipe2.ViewModels.CustomerVM
@{
Layout = null;
}
@{
ViewBag.Title = "Customer";
WebGrid grid = new WebGrid(canPage:false,canSort:false);
grid.Bind(Model.Customers,
autoSortAndPage: false
);
}
@using (Html.BeginForm())
{
<table>
<tr>
<td>
Name
</td>
 
Search WWH ::




Custom Search