dont see an empty text box inside the drop down

Anjali Agarwal 1,221 Reputation points

I have the following code on my web page. I am trying to use select2 so that user can type in the value inside the drop down.

<div class="card card-primary">

<div class="row">

    <div class="card-body">

        <div class="col-md-12">

            <form asp-action="Create">

              @*  <div asp-validation-summary="ModelOnly" class="text-danger"></div>*@

                <div class="form-group row">

                    <div class="col-sm-4">


                        <select id="ddlType" name="Name" class="form-control" asp-items="ViewBag.Select">

                            <option value="0">--Select Type--</option>




                <div class="form-group">

                    <input type="submit" value="Create" class="btn btn-primary" />







link rel="stylesheet" href="" />

<script type="text/javascript" src=""></script>

<script type="text/javascript" src=""></script>

<script type="text/javascript">

$(function () {




        tags: true,

        createTag: function (params) {

            return {

                id: params.term,

                text: params.term,

                newOption: true



        templateResult: function (data) {

            var $result = $("<span></span>");


            if (data.newOption) {

                $result.append(" <em>(new)</em>");


            return $result;





I don't have the script section because I have this in my layout page

<script src="~/lib/jquery/dist/jquery.min.js"></script>

<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

<script src="~/js/site.js" asp-append-version="true"></script>

await RenderSectionAsync("Scripts", required: false)

This is what I have in the controller.

 public async Task<IActionResult> Create()


           List<DocumentType> GetAllDocType =  await _documentTypeService.GetAllDocTypes();

		   SelectList Typo = new SelectList(GetAllDocType.DistinctBy(x=>x.Type), "Id", "Type");

           ViewBag.Select = Typo;

           return View();

A set of technologies in the .NET Framework for building web applications and XML web services.
3,762 questions
A Microsoft web application framework that implements the model-view-controller (MVC) design pattern.
1,049 questions
{count} votes

Accepted answer
  1. Bruce ( 48,481 Reputation points

    you should use the browser debug tools you would see the error. view page source and be sure the script includes are before the inline javascript.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful