ASP. net mvc series: Add query function for views, asp. netmvc

Source: Internet
Author: User

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

Related Article

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.