Title: ASP.NET Core MVC Select with dynamic searchig
Tags: javascript;asp.net;asp.net-mvc;asp.net-core
Question: I have a Login page, and I want to implement when an user type the username for example &quot;Jh&quot;, because he is called Jhon, then next to the Login form there is a selectlist, and listing all the usernames from the database that contains Jh, and it should be dynamic, I mean if the input changes then update the search automatically.
Here is my view
```<div class=&quot;row justify-content-center&quot;&gt;
<div class=&quot;col-md-7&quot;&gt;
    <form asp-action=&quot;Login&quot;&gt;
        <div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;</div&gt;
        @if (!string.IsNullOrEmpty(ViewBag.Message))
        {
            <span class=&quot;text-danger&quot;&gt;
                @ViewBag.Message
            </span&gt;
        }
        @Html.HiddenFor(x =&gt; x.ReturnUrl)
        <div class=&quot;form-group&quot;&gt;
            <label asp-for=&quot;UserId&quot; class=&quot;control-label&quot;&gt;</label&gt;
            <input asp-for=&quot;UserId&quot; class=&quot;form-control&quot; /&gt;
            <span asp-validation-for=&quot;UserId&quot; class=&quot;text-danger&quot;&gt;</span&gt;
        </div&gt;
        <div class=&quot;form-group&quot;&gt;
            <label asp-for=&quot;Password&quot; class=&quot;control-label&quot;&gt;</label&gt;
            <input asp-for=&quot;Password&quot; class=&quot;form-control&quot; /&gt;
            <span asp-validation-for=&quot;Password&quot; class=&quot;text-danger&quot;&gt;</span&gt;
        </div&gt;
        @*<div class=&quot;form-group&quot;&gt;
        <div class=&quot;checkbox&quot;&gt;
            <label&gt;
                <input asp-for=&quot;RememberLogin&quot; /&gt; @Html.DisplayNameFor(model =&gt; model.RememberLogin)
            </label&gt;
        </div&gt;
    </div&gt;*@

        <div class=&quot;form-group&quot;&gt;
            <input type=&quot;submit&quot; value=&quot;Bejelentkezés&quot; class=&quot;btn btn-primary w-100&quot; /&gt;
        </div&gt;
    </form&gt;
</div&gt;
        <div class=&quot;col-md-5&quot;&gt;
            <div class=&quot;form-group col-md-6&quot;&gt;
                <select asp-for=&quot;UserId&quot; asp-items=&quot;ViewBag.Users&quot; size=&quot;6&quot; multiple class=&quot;form-control&quot;&gt;</select&gt;
                <span asp-validation-for=&quot;UserId&quot; class=&quot;text-danger&quot;&gt;</span&gt;
            </div&gt;
        </div&gt;

</div&gt;

<script&gt;
    $(&quot;#search_id&quot;).keyup(function () {
        //call ajax method
    });
</script&gt;
```
Here is my controller (Im using stored procedures):
``` public IActionResult Login(string ReturnUrl = &quot;/&quot;)
    {
        LoginModel objLoginModel = new LoginModel();
        objLoginModel.ReturnUrl = ReturnUrl;

        string sqlQuery = &quot;execute GetUsers&quot;;
        var result = _context.GetUsers(sqlQuery);
        ViewBag.Users = new SelectList(result, &quot;UserId&quot;, &quot;UserId&quot;);
        return View(&quot;Login&quot;);
    }
```



Here is another answer: I write a simple demo here without any third part plugin, It is a basic demo to show how to achieve dynamic search, You can refer and make some changes to meet the needs of your own project. I hople it is what you want.
Model
```public class Student
{
    public string Id { get; set; }
    public string Name { get; set; }
}
```
View
```@model Student

<input asp-for=&quot;@Model.Name&quot; oninput=&quot;Search(this.value)&quot;/&gt;

<div id=&quot;result&quot;&gt;</div&gt;

@section Scripts
{
    <script&gt;
       function Search(data) {
          var value ={
            &quot;name&quot;: data    
          }
          
          $.post({
                url: 'https://localhost:7209/Home/Download1',
                ethod: 'Post',
                data: value,                               
                success: function (data) {
                    result = '';
                    for (var i = 0;i<data.length;i++){
                        result = result +'<tr&gt;<td&gt;'+data[i].id+'</td&gt;<td&gt;'+data[i].name+'</td&gt;</tr&gt;';
                    }  
                    document.getElementById(&quot;result&quot;).innerHTML = '<table class=&quot;table table-striped table-bordered zero-configuration dataTable&quot; role=&quot;grid&quot;&gt;'
                                                   +'<thead&gt;<tr&gt;<th&gt;Id</th&gt;<th&gt;Name</th&gt;</tr&gt;</thead&gt;'                                                                
                                                   +'<tbody&gt;'+result+'</tbody&gt;'
                                                   +'</table&gt;';
                    
                }
          })
       }
    
    </script&gt;
}
```
Home/Download1
```[HttpPost]
    public IActionResult Download1(string name)
    {
        
        //For testing convenience, I just hard code here, you can change it and select data from database

        var result = Students.Where(x =&gt; x.Name.Contains(name)).ToList(); 
        return Json(result);
    }
```
Demo


Comment for this answer: HI @kajahun123, If my answer help you resolve your issue, could you please accept as answer? Thanks.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:07/05/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><asp.net><asp.net-mvc><asp.net-core>', 'Title': 'ASP.NET Core MVC Select with dynamic searchig', 'ViewCount': 75, 'id': 72865391, 'user_AboutMe': '', 'user_AccountId': 20930930.0, 'user_DisplayName': 'kajahun123', 'user_Reputation': 11.0, 'user_Views': 22.0, 'user_id': 16104582.0}}