//Search for movies and arrange them by movie category PublicActionResult Index (stringMoviegenre,stringsearchstring) { //you can put an empty generic collection of type string varGenrelst =Newlist<string>(); //The following code retrieves all types of LINQ queries from the database. varGenreqry = fromDinchdb. Movies byd.genreSelectd.genre; //Put the non-repeating movie category at the end of the collectionGenrelst.addrange (Genreqry.distinct ()); //Put the query data in the View.bag.Viewbag.moviegenre =Newselectlist (GENRELST); //Query Movie name varMovies = fromMinchdb. MoviesSelectm; if(!String.IsNullOrEmpty (searchstring)) {Movies= movies. Where (s=>s.title.contains (searchstring)); } //Query movies by type. How to check the Moviegenre parameter. //if it is not empty, the code further constrains the movie query to restrict the selected movie to the specified type if(!String.IsNullOrEmpty (moviegenre)) {Movies= movies. Where (p=>p.genre==moviegenre); } returnView (Movies); } The code in the view @model IEnumerable<Movies.Models.Movie>@{Viewbag.title="Index";}@Html. ActionLink ("Create New","Create") @*using's usage, remember?@ @using (Html.BeginForm ("Index","Movies", Formmethod.get)) //If this first executes the HttpGet method in the controller. If the beginform does not have parameters to execute the HttpPost method{ <p> movie Name: @Html. TextBox ("searchstring") <br/>type: @Html. DropDownList ("moviegenre","All Types") <input type="Submit"Value="Enquiry"/> </p> }</p><tableclass="Table"> <tr> <th>@Html. Displaynamefor (Model=model. Title)</th> <th>@Html. Displaynamefor (Model=model. ReleaseDate)</th> <th>@Html. Displaynamefor (Model=model. GENRE)</th> <th>@Html. Displaynamefor (Model=model. Price)</th> <th></th> </tr>@foreach (varIteminchModel) { <tr> <td>@Html. Displayfor (ModelItem=item. Title)</td> <td>@Html. Displayfor (ModelItem=item. ReleaseDate)</td> <td>@Html. Displayfor (ModelItem=item. GENRE)</td> <td>@Html. Displayfor (ModelItem=item. Price)</td> <td>@Html. ActionLink ("Modify","Edit",New{id=item.id}) |@Html. ActionLink ("Xiang Love","Details",New{id=item.id}) |@Html. ActionLink ("Delete","Delete",New{id=item.id}) </td> </tr>}</table>
The MVC operation LocalDB Database, through the movie type and the name to query the movie, in the controller writes the method as well as the page code, own reference.