无法使下拉列表可搜索

时间:2020-07-31 20:04:06

标签: c# html css asp.net

我的视图页面上有一个下拉列表,但它不是可搜索的下拉列表,这就是我填充下拉列表值的方式

C:\Users\ddjan\Downloads\sip>C:\Python\Python38\python configure.py -p win32-g++
This is SIP 4.19.23 for Python 3.8.2 on win32.
The SIP code generator will be installed in C:\Python\Python38.
The sip.h header file will be installed in C:\Python\Python38\include.
The sip module will be installed in C:\Python\Python38\Lib\site-packages.
The sip.pyi stub file will be installed in
C:\Python\Python38\Lib\site-packages.
The default directory to install .sip files in is C:\Python\Python38\sip.
Creating sipconfig.py...
Creating top level Makefile...
Creating sip code generator Makefile...
Creating sip module Makefile...

C:\Users\ddjan\Downloads\sip>make
make[1]: Entering directory `C:/Users/ddjan/Downloads/sip/sipgen'
makefile:29: warning: overriding commands for target `.c.o'
makefile:26: warning: ignoring old commands for target `.c.o'
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o main.o main.c
main.c: In function 'warning':
main.c:528:9: warning: 'wstr' may be used uninitialized in this function [-Wmaybe-uninitialized]
  528 |         fprintf(stderr, "%s: %s: ", sipPackage, wstr);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o transform.o transform.c
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o gencode.o gencode.c
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o extracts.o extracts.c
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o export.o export.c
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o type_hints.o type_hints.c
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o heap.o heap.c
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o parser.o parser.c
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o lexer.o lexer.c
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -Wl,-s -o sip.exe main.o transform.o gencode.o extracts.o export.o type_hints.o heap.o parser.o lexer.o
make[1]: Leaving directory `C:/Users/ddjan/Downloads/sip/sipgen'
make[1]: Entering directory `C:/Users/ddjan/Downloads/sip/siplib'
makefile:29: warning: overriding commands for target `.c.o'
makefile:26: warning: ignoring old commands for target `.c.o'
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o siplib.o siplib.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from siplib.c:20:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
siplib.c: In function 'wrapInstance':
siplib.c:1722:42: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
 1722 |         return sip_api_convert_from_type((void *)addr, wt->wt_td, NULL);
      |                                          ^
siplib.c: In function 'parsePass2':
siplib.c:5812:32: warning: 'owner' may be used uninitialized in this function [-Wmaybe-uninitialized]
 5812 |                         *owner = arg;
      |                         ~~~~~~~^~~~~
siplib.c: In function 'slot_richcompare':
siplib.c:11450:52: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
11450 |     if ((f = (PyObject *(*)(PyObject *,PyObject *))findSlot(self, st)) == NULL)
      |                                                    ^~~~~~~~~~~~~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o apiversions.o apiversions.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from apiversions.c:20:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o descriptors.o descriptors.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from descriptors.c:20:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o qtlib.o qtlib.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from qtlib.c:21:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o threads.o threads.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from sipint.h:24,
                 from threads.c:22:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o objmap.o objmap.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from sipint.h:24,
                 from objmap.c:23:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o voidptr.o voidptr.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from voidptr.c:20:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o array.o array.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from array.c:20:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
gcc -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o int_convertors.o int_convertors.c
In file included from C:\Python\Python38\include/Python.h:85,
                 from int_convertors.c:38:
C:\Python\Python38\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  123 | PyAPI_FUNC(int) _PyTime_FromTimeval(_PyTime_t *tp, struct timeval *tv);
      |                                                           ^~~~~~~
C:\Python\Python38\include/pytime.h:130:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  130 |     struct timeval *tv,
      |            ^~~~~~~
C:\Python\Python38\include/pytime.h:135:12: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
  135 |     struct timeval *tv,
      |            ^~~~~~~
g++ -c -O2 -Wall -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -IC:\Python\Python38\include -o bool.o bool.cpp
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -shared -Wl,-subsystem,console -Wl,-s -o sip.pyd siplib.o apiversions.o descriptors.o qtlib.o threads.o objmap.o voidptr.o array.o int_convertors.o bool.o -LC:\Python\Python38\libs -lpython38
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Python\Python38\libs/python38.lib(python38.dll): recognised but unhandled machine type (0x8664) in Import Library Format archive
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Python\Python38\libs/python38.lib: error adding symbols: file format not recognized
collect2.exe: error: ld returned 1 exit status
make[1]: *** [sip.pyd] Error 1
make[1]: Leaving directory `C:/Users/ddjan/Downloads/sip/siplib'
make: *** [all] Error 2

这就是我在视图中进行设置的方式

 public ActionResult SpecialOrderSummary(int? id)
        {
            ItemViewModel model = (ItemViewModel)TempData["model"];
            TempData.Keep("model");
           
            var part = (from i in db.Parts.Where(x => x.deleted == false)
                        select new
                        {
                            partID = i.ID,
                            partName = i.PartID  + i.Name
                        }).OrderBy(x => x.partName).ToList();
                   
            ViewBag.PartID = new SelectList(part, "partID", "partName");
                   
            return View(model);
        }

我已经在系统的其他部分以相同的方式进行了设置,并且可以正确地使下拉列表可搜索,但不适用于这种情况。下拉菜单看起来也与通常不同,

correct way

但是目前我的下拉列表看起来像这样

not searchable

1 个答案:

答案 0 :(得分:0)

Asp.Net默认情况下不支持可搜索的下拉菜单。您可以使用select2下拉列表,它是普通下拉列表的包装。

尝试一下:

步骤1::导入必要的CSS和脚本:

 <!-- Bootstrap css-->
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

 <!-- Select2 css-->
 <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
  

第2步:您的实际下拉列表

@Html.DropDownList("PartID", null, "-- Select --", htmlAttributes: new { @class = "form-control chosen-select Part-select" })

步骤3:使用jquery在页面加载时绑定可搜索的select2下拉列表

 <!-- JQuery script-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Select2 script-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>

 $(document).ready(function(){
   $('.chosen-select').select2({     // .chosen-select is class name(from your dropdown)
            placeholder: "Select"
        });
  });

样本输出:

enter image description here

注意:

  • 脚本的顺序非常重要。正如我在这里提到的那样,提及他们的订单。
  • 最佳做法是提及上面的样式链接(在head标签内)和下面的脚本(在您的body标签内)
  • 如果您在这里遇到困难,请访问以下链接:Codepen-Searchable Dropdown demo