Skip to content

Advanced search page in your MVC app in 5 minutes

Problem

  1. You have an ASP.NET MVC project which works with some database (directly or through EntityFramwork).
  2. You have a request for a new page in your application with "advanced search" functionality where users will be able to build quite complicated queries to underlying DB and get the result instantly
  3. You need this functionality, you know, "for yesterday" :)

Solution

1. Open your project in Visual Studio

2. Go to Package Manager (PM) Console

Use the menu item if the console is not opened currently:
Tools | Nuget Package Manager | Package Manager Console

3. Install EasyQuery Nuget package

Just type in PM console


PM> Install-Package EasyQuery.Mvc.Scaffolding

4. Scaffold an advanced search page

Type:


PM> Scaffold EasyQuery.MvcController {ControllerName} -ConnectionName {ConnectionName}

to add a new controller and corresponding view page.

Here {ConnectionName} parameter is the name of your connection defined in Web.config file.

Example:


PM> Scaffold EasyQuery.MvcController AdvancedSearch -ConnectionName DefaultConnection

in case you are using EntityFramework use -DbContext parameter of Scaffold command. For example:


PM> Scaffold EasyQuery.MvcController AdvancedSearch -DbContext NorthwindContext

5. Open your advanced search page in browser

Now you can try to open your new page in browser and check how it works. If you named your new controller (and view) exactly as in examples above ("AdvancedSearch") then you can type:

http://localhost:[port]/AdvancedSearch

That's all!

To see the whole process described above in action you can visit this video page on YouTube.