MVC Program implements AutoComplete function

Source: Internet
Author: User

In order to strengthen the skill of MVC, strengthen the practice is the thing. Insus.net this time to realize the AutoComplete function of the text box.

Create a table in data [PinYin]:


Insert some data:

INSERT into [dbo]. [PinYin] ([Word]) VALUES (' A '), (' Ai '), (' an '), (' Ang '), (' AO '), (' Ba '), (' Bai '), (' Ban '), (' Bei '), (' Ben '), (' Bi '), (' Bian '), (' Bie '), (' Bin ' ), (' Bing '), (' Ca '), (' Cai '), (' Cang '), (' Cao '), (' CEng '), (' Cha '), (' Chai '), (' Che '), (' Chen '), (' Cheng '), (' Chong '), (' Chou '), (' FA '), (' Fan '), (' Fang '), (' Fei '), (' Fen '), (' Feng '), (' GA '), (' Gai '), (' Gan '), (' Gang '), (' Gao '), (' GE '), (' GEi ') , (' Gen '), (' Geng '), (' Gong '), (' Gou '), (' Gu '), (' Gua '), (' Guai ') GO


and create a stored procedure Usp_pinyin_getword:



Under the models directory of the MVC application, create a pinyin model:



Read the database data, create an entity, expand the Entities directory:



Next, in the application right-click, start Manage NuGet Packages ...



To install the jquery UI:




It will install the relevant CSS and JS separately in the application content:


and Scripts Directories:


Next, we need to create a handler, which is a bit like a service that requests and processes the text entered in the text box where the user is located. You first need to create a handlers directory under the application, and if so, skip this step.


Note that code # # # line code, if modified with added namespace namespace, you also have to open HANDLER.ASHX markup Add and modify namespace:



Now we're just practicing, in the Controllers directory, open the HomeController controller to create a actionresult:

When everything is well written, you can write the view:


The above code, #5步可以根据实际需要, is the value or text that is ultimately displayed in the text box.

Real-time Operation Demo:

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.