The use of AutoComplete plugins under MVC

Source: Internet
Author: User

AutoComplete plug-in function is similar to Google Suggest function, can be in the user input query conditions, automatically prompt users a number of entries, convenient for users to quickly query. Below we describe how the next AutoComplete plugin is used under MVC.

First, you need to download the AutoComplete plugin, which is: http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

Next, you need to introduce two files (except jquery files) on the page, respectively, Jquery.autocomplete.js and JQUERY.AUTOCOMPLETE.CSS, the code is as follows:

<script src= "@Url. Content (" ~/content/autocomplete/jquery.autocomplete.js ")" Type= "Text/javascript" ></ Script><link href= "@Url. Content (" ~/content/autocomplete/jquery.autocomplete.css ")" rel= "stylesheet" type= " Text/css "/>

The front-end page just needs to add a text box with the following code:

<input type= "text" name= "Higheruserid" id= "Higheruserid"/>

The JS code you need to write is as follows:

<script type= "Text/javascript" >            $ (function () {                $ ("#HigherUserID"). AutoComplete ("/user/ Getuserbyusername ", {                dataType:" JSON ",                minchars:0,                width:200,                showname:" Truename ",                Selfaction:salesdeletename,                cachelength:0,                autofill:false,                formatitem:function (row, I, max) {                    return i + "/" + Max + ": \" "+ row. Truename + "\" ["+ row. Usercode + "]";                },                formatresult:function (row) {                    return row. truename;                }            }). Result (function (event, row) {                           });            })        </script>

The background code retrieves the person information according to the condition, pagination display, returns to the front end a JSON data:

Public ActionResult  Getuserbyusername (string q)        {            int _totalcount = 0;            Queryuser query = new Queryuser ();            Query.truename = q;            Query.state = "0";            var userlist = userservice.getusersbypage (query, ten, 1, out _totalcount);            ilist<userinfo> users = userlist. Tolist<userinfo> ();            Return Json (Users, Jsonrequestbehavior.allowget);        }





The use of AutoComplete plugins under MVC

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.