ASP. NET MVC build Project Background UI Framework-11, Auto load dropdown box query

Source: Internet
Author: User

ASP. NET MVC build Project Background UI Framework-1, background main frame

Requirements: In the query record, enter the first word, automatically the word begins with the relevant records to find out, enter 2 words to filter the records beginning with the two children, and so on.

Suddenly to use this function, the impression has written this feature of the article, all of a sudden can not find, had to re-posted out of the memo. Recently the blog has not been updated for nearly 2 months, because these two months have been writing books behind closed doors.

Introduction of JS and css:http://download.csdn.net/detail/zouyujie1127/9550279

<link href= "~/libs/autocomplete/css/ui-lightness/jquery-ui-1.8.17.custom.css" rel= "stylesheet"/>

<script src= "~/libs/autocomplete/js/jquery-ui-1.8.17.custom.min.js" ></script>

Add the following JS code to the View interface:

<script type= "Text/javascript" >
$ (function () {
Getcustomerlist ("Cusname");});
//Automatically load customer listfunctionGetcustomerlist (TXT) {if (txt = = Undefined | | txt = = "")Return; $("#"+TXT). AutoComplete ({source: "/customer/getcusnamelist", minlength:1});//$ ("#" + txt). focus (function () {// if ($ (this). val () = = "Please enter username") {// $ (this). CSS ("Color", "Black"). Val (""); // //////cursor left //// $ (this). CSS ("Color", "Gray"). Val ("Please enter user name"); // //});} 

</script>

The list method in Customercontroller is as follows:

        /// <summary>        ///get the Customer list fuzzy query/// </summary>        /// <param name= "term" ></param>        /// <returns></returns>         Public stringGetcusnamelist (stringTerm ) {            if(string. Isnullorwhitespace (term))return NULL; varDataSource = Customerinfo.getbyfilter (Newcustomerfilter {cusname =Term }); List<string> list = Datasource.select (x=>x.cusname).            ToList (); //Serializing ObjectsSystem.Web.Script.Serialization.JavaScriptSerializer js =NewSystem.Web.Script.Serialization.JavaScriptSerializer (); returnJS. Serialize (list.        ToArray ()); }

ASP. NET MVC build Project Background UI Framework-11, Auto load dropdown box query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.