Home Asp.net MVC Search functionality in ASP.NET MVC with Ajax

Search functionality in ASP.NET MVC with Ajax

7 min read

In this tutorial will teach the Search Functionality In ASP.NET MVC with Ajax step by step.How to search the records in asp.net mvc with ajax this tutorial help you to learn.

Database First Approach

First Step create the database on Microsoft sqlserver database.

In this example we have created the database which name is bank inside the database create the table name is account

Account table consist of the following columns accno,accname,balance

After done the stuff.open up the .net  application and create the new mvc project.

First step generated the Models.how to generated  the models i attached the video tutorial below.Model which is interact with database.

After that inside the controllers folder there will be the controller which name is HomeController.

Paste the Following Code

using AccountBalance.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AccountBalance.Controllers
    public class HomeController : Controller

        bankEntities dc = new bankEntities();
        public ActionResult Index()
            return View();

        public JsonResult Getid(String Id)
            var std = dc.accounts.Where(a => a.accno == Id).FirstOrDefault();
            return Json(std, JsonRequestBehavior.AllowGet);


After that Create the Layouts. Layout is inside the shared folder


<!DOCTYPE html>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    @RenderSection("styles", false)

    <div class="container-fluid bg-2 text-center">

    @RenderSection("scripts", required: false)


    ViewBag.Title = "Index";

<div class="row">
    <div class="col-sm-8">
        @using (Html.BeginForm("Index", "home", FormMethod.Post, new { id = "popupForm" }))

            <table class="table table-bordered">
                <h2> Bank Balance Checking  </h2>
                    <th>Account No</th>
                    <th>Account Holder Name</th>
                <tr align="center">
                        <input type="text" class="form-control" placeholder="Account No" id="accno" name="accno" size="50px">


                        <input type="text" class="form-control" id="accname" size="25px" name="accname"
                               placeholder="price" disabled>
                        <input type="text" class="form-control" id="balance" name="balance"
                               placeholder="qty" size="25px" required>



<hr />


@section scripts{

    <script src="~/Scripts/jquery-3.4.1.js"></script>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/jquery.validate.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>


        function getAccountcode() {
            $("#accno").keyup(function (e) {
                var q = $("#accno").val();
                if ($('#accno').val().length === 0) {
                        title: 'Error!',
                        content: "Please Enter the Account",
                        type: 'red',
                        autoClose: 'ok|2000'
                    return false;
                    type: "POST",
                    url: '/home/Getid?id=' + $("#accno").val(),
                    dataType: "JSON",
                    success: function (data) {
                    error: function (xhr, status, error) {
                        //  alert(xhr,status);
                return true;

@section styles{
    <link href="~/Content/bootstrap.css" rel="stylesheet" />

    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
    <link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">

i have attached the video link below. which will do this tutorials step by step




    Load More Related Articles
    Load More By admin
    Load More In Asp.net MVC

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Check Also

    Laravel 11 CRUD Mastering RESTful API MVC with Repository Pattern

    In this tutorial will teach Laravel 11 Api MVC with Repository Pattern Crud Application st…