We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to add text dynamically in the Autocomplete control when it is not present in the suggestion list?

Description

In order to add a new item to the Autocomplete control, use AllowAddNew and AddNewText API’s. AllowAddNew is used to allow or restrict the Autocomplete control from adding a new item to the list. It accepts Boolean value. By default, the value of the AllowAddNew property is false. You can set it to true to add new text in the Autocomplete control. An API called AddNewText is used to add new item to the list items. It accepts String value. By default, the value of the AddNewText API is Add New.

Solution

To add new text in the Autocomplete control, enable AllowAddNew API, so that you can add a new text to the Autocomplete text box. After setting the AllowAddNew API to true, add new text by using the API AddNewText.

 [.cshtml]

Note: AddNewText can be used in the Visual mode only.

The sample is attached for adding text in the Autocomplete control and it can be downloaded from the following location.

Sample Location: Sample

In the attached sample, the AllowAddNew and AddNewText APIs are included. When you type the text that is not present in the list, it shows the text given in the AddNewText API.

After selecting the entered text in the Autocomplete popup, it is added in the Autocomplete control as shown in the following screenshot.

Thus, you can add text in the Autocomplete control.

Article ID: Published Date: Last Revised Date: Platform: Control:
4763 05/05/2015 05/05/2015 ASP.NET MVC AutoComplete
Did you find this information helpful?
Comments
Chris Morris Feb 14, 2018

How do you prevent duplicates from coming up in the list when you have Allow Add New in there along with Multiple values?

Reply
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.