Here I added code with a description in a green comment mark at one place for better and faster understanding.
Step 7
We need to add JS files from Nuget package manager for posting data to Controller without page refresh. If you want to work Ajax.BeginForm functionality properly you should not forget to add the reference of the following jQuery library as mentioned in the screenshot. Download library using NuGet and reference into the project.
Step 8
Add some flavor for the view page by modifying in _Layout.cshtml.
Code Ref
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>@ViewBag.Title - My ASP.NET Application</title>
- @Styles.Render("~/Content/css")
- @Scripts.Render("~/bundles/modernizr")
- </head>
- <body>
- <div class="navbar navbar-fixed-top" style="background-color:orangered;">
- <h4 style="color:white; text-align:center">Filter Records Using Multiple Parameter In MVC</h4>
- </div>
- <div class="container body-content">
- @RenderBody()
- <hr />
- <footer>
- <p style="background-color: Yellow; font-weight: bold; color:blue; text-align: center; font-style: oblique">© @DateTime.Now.ToLocalTime()</p> @*Add Date Time*@
- </footer>
- </div>
-
- @Scripts.Render("~/bundles/jquery")
- @Scripts.Render("~/bundles/bootstrap")
- @RenderSection("scripts", required: false)
- </body>
- </html>
OUTPUT
The landing page is shown as mentioned below:
Then filter data using gender and post name.
Then filter data using gender.
Then filter data using name.
Then filter data using from date and to date.
Then filter records using gender and date.
Then filter records using all parameters.
If no records are found then it is shown like this.
Then the alert is mentioned between from date and to date compare. Pic-1
Then the alert is mentioned between from date and to date compare. Pic-2
Link To Source Code
In this article, we have learned,
- About dynamic sql with stored procedure and its merits
- Passing multiple parameters for filtering records
- Posting data to controller without page refresh using Ajax.BeginForm functionality
- Managing alert message in MVC and design view using layout