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.

Source: Internet
Author: User
Tags actionlink

  //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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.