ASP. net mvc series: Add query function for views, asp. netmvc
First, add a query method in MoviesController. The Code is as follows:
Public ActionResult SearchIndex (string title) {// query the movie table var movies = from m in db. Movies select m; if (! String. isNullOrEmpty (title) {// query the movies = movies. where (m => m. title. contains (title);} return View (movies );}
Create a view for the SearchIndex method, and select the model class Movie and framework template List of the view.
After adding the view, we enter the URL http: // localhost: 60534/Movies/searchindex in the browser? Title = 123 (I have added the title = 3 data in the database), and it can query data for us.
Now we add a query button in the SearchIndex view to submit the query conditions through the button.
@using (@Html.BeginForm()) { <p> Titile:@Html.TextBox("title")<br /> <input type="submit" value="Filter" /> </p> }
A basic query function is implemented.
http://www.asp.net/mvc/overview/older-versions/getting-started-with-aspnet-mvc4/examining-the-edit-methods-and-edit-view